diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 14:25:07 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-22 14:25:07 +0100 |
commit | 9a7d578b12ca6f869f7561f11ee0837a12b58a84 (patch) | |
tree | e5e645af0b6858bc603caa2f3f95335bf4e44050 /ctrack/register/css.py | |
parent | 113f9483a2b2863f3e7e176285e9031593843eda (diff) |
failing tests but lots of progress on html builders
Diffstat (limited to '')
-rw-r--r-- | ctrack/register/css.py | 116 |
1 files changed, 52 insertions, 64 deletions
diff --git a/ctrack/register/css.py b/ctrack/register/css.py index 0c49fcd..7567e9d 100644 --- a/ctrack/register/css.py +++ b/ctrack/register/css.py @@ -1,7 +1,6 @@ -from dataclasses import dataclass from typing import NamedTuple, List -from ctrack.register.models import EventType, EventBase, CAFSingleDateEvent +from ctrack.register.models import EventType, EventBase class TagAttributes(NamedTuple): @@ -9,73 +8,62 @@ class TagAttributes(NamedTuple): id_str: str -def tag_attrs(event) -> TagAttributes: - if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: - return TagAttributes( - inline_style='style="background-color: green; color: white;"', - id_str="caf-initial-received-event", - ) - if event.type_descriptor == EventType.CAF_INITIAL_REVIEW_COMPLETE.name: - return TagAttributes( - inline_style='style="background-color: green; color: white;"', - id_str="caf-initial-review-complete-event", - ) - - -template = ( - "<tr>\n" - " <td>{0}</td>\n" - " {1}\n" - " {2}\n" - " <td>OES Revisions Submitted</td>\n" - " <td>Validation Agreed</td>\n" - " <td>Improvement Plan Submitted</td>\n" - " <td>Improvement Plan Review</td>\n" - "</tr>\n" -) - - class Swimlane: def __init__(self, org_name: str, events: List[EventBase]): self.events = events + self.attrs_added = [] self.org_name = org_name - self.slots = CAFSwimlaneSlots(*events) # type: CAFSwimlaneSlots + self._process_args() - @property - def tr(self): - initial_submitted_str = "".join( - [ - "<td ", - tag_attrs(self.slots.initial_submitted).inline_style, - ">", - self.slots.initial_submitted.type_descriptor, - "</td>" - ] - ) - revision_completed_str = "".join( - [ - "<td ", - tag_attrs(self.slots.reviewed).inline_style, - ">", - self.slots.reviewed.type_descriptor, - "</td>" - ] - ) - return template.format( - self.org_name, initial_submitted_str, revision_completed_str - ) + def tag_attrs(self, event) -> TagAttributes: + if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: + try: + self.attrs_added.pop( + self.attrs_added.index(EventType.CAF_INITIAL_CAF_RECEIVED.name) + ) + except ValueError: + pass + return TagAttributes( + inline_style=' style="background-color: green; color: white;"', + id_str="caf-initial-received-event", + ) + if event.type_descriptor == EventType.CAF_INITIAL_REVIEW_COMPLETE.name: + try: + self.attrs_added.pop( + self.attrs_added.index(EventType.CAF_INITIAL_REVIEW_COMPLETE.name) + ) + except ValueError: + pass + return TagAttributes( + inline_style=' style="background-color: green; color: white;"', + id_str="caf-initial-review-complete-event", + ) + def table_row_builder(self): + if len(self.events) == 0: + 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 = "\n".join(_tds) + empties_strs = "\n".join(empties) + return "".join(["<tr>\n", f"<td>{org}</td>\n", tds, "\n", empties_strs, "\n", "</tr>"]) -@dataclass(frozen=True) -class CAFSwimlaneSlots: - """ - The pre-compliance stages we expect. - """ + def _process_args(self): + for v in EventType: + setattr(self, v.name, None) + self.attrs_added.append(v.name) + for e in self.events: + setattr(self, str(e.type_descriptor), e) - initial_submitted: CAFSingleDateEvent = None - reviewed: CAFSingleDateEvent = None - revisions_submitted: CAFSingleDateEvent = None - validation_agreed: CAFSingleDateEvent = None - improvement_plan_submitted: CAFSingleDateEvent = None - improvement_plan_reviewed: CAFSingleDateEvent = None - improvement_plan_agreed: CAFSingleDateEvent = None + @property + def tr(self): + return self.table_row_builder() |