diff --git a/models/database.py b/models/database.py index 897ae886be16e8527fe4fcda62e92f09fa0b9c38..2a6d373df10438c247d046deaca2215654762edd 100644 --- a/models/database.py +++ b/models/database.py @@ -218,6 +218,12 @@ class Protocol(db.Model): def get_originating_todos(self): return [todo for todo in self.todos if self == todo.get_first_protocol()] + def get_open_todos(self): + return [ + todo for todo in self.protocoltype.todos + if not todo.is_done() + ] + def has_compiled_document(self): candidates = [ document for document in self.documents @@ -472,6 +478,13 @@ class Todo(db.Model): self.get_state_plain() ) + def render_template(self): + parts = ["todo", self.who, self.description, self.state.get_name()] + if self.state.needs_date(): + parts.append(date_filter(self.state)) + parts.append("id {}".format(self.get_id())) + return "[{}]".format(";".join(parts)) + class TodoProtocolAssociation(db.Model): __tablename__ = "todoprotocolassociations" diff --git a/templates/protocol-template.txt b/templates/protocol-template.txt index 4f1516f532d83cb3dab051e8933c94fd51888d26..13b2faf4905d53febf88f805c1b96bb847121a30 100644 --- a/templates/protocol-template.txt +++ b/templates/protocol-template.txt @@ -8,9 +8,10 @@ {% macro render_top(top) %} {TOP {{top.name}} {% if top.name == "Todos" %} - {% if protocol.todos|length > 0 %} - {% for todo in protocol.todos %} - [todo;{{todo.who}};{{todo.description}};id {{todo.get_id()}}]; + {% set todos=protocol.get_open_todos() %} + {% if todos|length > 0 %} + {% for todo in todos %} + {{todo.render_template()}}; {% endfor %} {% else %}