diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 16:04:04 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 16:04:04 +0100 |
commit | cfaa49c5416cca7473abe0523c767d188ea447ab (patch) | |
tree | 085ef6988de0c47273bd3548e130d6fd55c4453a | |
parent | 9a7d578b12ca6f869f7561f11ee0837a12b58a84 (diff) |
getting there but test failing
-rw-r--r-- | ctrack/register/css.py | 34 | ||||
-rw-r--r-- | ctrack/register/models.py | 3 | ||||
-rw-r--r-- | ctrack/register/tests/test_css.py | 7 |
3 files changed, 34 insertions, 10 deletions
diff --git a/ctrack/register/css.py b/ctrack/register/css.py index 7567e9d..28d2876 100644 --- a/ctrack/register/css.py +++ b/ctrack/register/css.py @@ -12,9 +12,15 @@ class Swimlane: def __init__(self, org_name: str, events: List[EventBase]): self.events = events self.attrs_added = [] + self.attrs_ordered = [] self.org_name = org_name self._process_args() + def _sort_func(self, type_name): + for e in self.attrs_ordered: + if list(type_name.keys())[0] == e[1]: + return e[0] + def tag_attrs(self, event) -> TagAttributes: if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: try: @@ -44,23 +50,31 @@ class Swimlane: raise ValueError("Cannot handle an empty list") tmpl = "<td{0}>{1}</td>" org = self.events[0].related_caf.organisation.name - _tds = [ - tmpl.format(self.tag_attrs(e).inline_style, e.type_descriptor) - for e in self.events - ] - empties = [ - tmpl.format("", e) - for e in self.attrs_added - if e[:3] == "CAF" - ] + _tds = sorted( + [ + { + e.type_descriptor: tmpl.format( + self.tag_attrs(e).inline_style, e.type_descriptor + ) + } + for e in self.events + ], + key=self._sort_func, + ) + empties = [{e: tmpl.format("", e)} for e in self.attrs_added if e[:3] == "CAF"] + _tds = [list(x.values())[0] for x in _tds] + empties = [list(x.values())[0] for x in empties] tds = "\n".join(_tds) empties_strs = "\n".join(empties) - return "".join(["<tr>\n", f"<td>{org}</td>\n", tds, "\n", empties_strs, "\n", "</tr>"]) + return "".join( + ["<tr>\n", f"<td>{org}</td>\n", tds, "\n", empties_strs, "\n", "</tr>"] + ) def _process_args(self): for v in EventType: setattr(self, v.name, None) self.attrs_added.append(v.name) + self.attrs_ordered = list(enumerate(self.attrs_added)) for e in self.events: setattr(self, str(e.type_descriptor), e) diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 475de9e..375521d 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -13,6 +13,9 @@ from ctrack.users.models import User class EventType(Enum): + """ + This is important - throughout the codebase! Do not fuck with me. + """ MEETING = auto() PHONE_CALL = auto() VIDEO_CALL = auto() diff --git a/ctrack/register/tests/test_css.py b/ctrack/register/tests/test_css.py index 301c715..fe530bd 100644 --- a/ctrack/register/tests/test_css.py +++ b/ctrack/register/tests/test_css.py @@ -129,5 +129,12 @@ def test_table_row_builder(user, caf): f"<td>{caf.organisation.name}</td>\n" '<td style="background-color: green; color: white;">CAF_INITIAL_CAF_RECEIVED</td>\n' '<td style="background-color: green; color: white;">CAF_INITIAL_REVIEW_COMPLETE</td>\n' + "<td>CAF_FEEDBACK_EMAILED_OES</td>\n" + "<td>CAF_RECEIVED</td>\n" + "<td>CAF_EMAILED_ROSA</td>\n" + "<td>CAF_VALIDATION_SIGN_OFF</td>\n" + "<td>CAF_VALIDATION_RECORD_EMAILED_TO_OES</td>\n" + "<td>CAF_PEER_REVIEW_PERIOD</td>\n" + "<td>CAF_VALIDATION_PERIOD</td>\n" "</tr>" ) |