From e43f55f99880ab02e4f61aef250b3e489fec45aa Mon Sep 17 00:00:00 2001 From: Dan Braghis <dan.braghis@torchbox.com> Date: Tue, 20 Mar 2018 10:21:42 +0000 Subject: [PATCH] Add last update information to the submission table --- opentech/apply/activity/models.py | 3 + opentech/apply/funds/tables.py | 4 +- .../funds/templates/funds/tables/table.html | 57 +++++++++++++++---- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/opentech/apply/activity/models.py b/opentech/apply/activity/models.py index 253927595..8b98bd733 100644 --- a/opentech/apply/activity/models.py +++ b/opentech/apply/activity/models.py @@ -27,6 +27,9 @@ class ActivityQuerySet(BaseActivityQuerySet): def comments(self): return self.filter(type=COMMENT) + def actions(self): + return self.filter(type=ACTION) + class ActivityBaseManager(models.Manager): def create(self, **kwargs): diff --git a/opentech/apply/funds/tables.py b/opentech/apply/funds/tables.py index fc89cf095..6062401ff 100644 --- a/opentech/apply/funds/tables.py +++ b/opentech/apply/funds/tables.py @@ -27,13 +27,15 @@ class SubmissionsTable(tables.Table): stage = tables.Column(verbose_name="Type", order_by=('status',)) page = tables.Column(verbose_name="Fund") comments = tables.Column(accessor='activities.comments.all', verbose_name="Comments") + last_update = tables.Column(accessor='activities.actions.last', verbose_name="Last update", visible=False) class Meta: model = ApplicationSubmission order_by = ('-submit_time',) fields = ('title', 'status_name', 'stage', 'page', 'round', 'submit_time') sequence = fields + ('comments',) - template = 'funds/tables/table.html' + extra_columns = ('last_update',) + template_name = 'funds/tables/table.html' row_attrs = { 'class': make_row_class } diff --git a/opentech/apply/funds/templates/funds/tables/table.html b/opentech/apply/funds/templates/funds/tables/table.html index e86bb739b..399b02cb8 100644 --- a/opentech/apply/funds/templates/funds/tables/table.html +++ b/opentech/apply/funds/templates/funds/tables/table.html @@ -1,29 +1,62 @@ {% extends 'django_tables2/table.html' %} -{% load table_tags %} +{% load table_tags django_tables2 %} {# example of how to extend the table template #} {% block table.tbody.row %} - {{ block.super }} + <tr {{ row.attrs.as_html }} data-record-id="{{ row.record.id }}"> + {% for column, cell in row.items %} + <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td> + {% endfor %} + </tr> {% with submission=row.record %} {# placeholder for example data row #} - <tr class="child"> - <td>Applicant: {{ submission.full_name }}</td> + <tr class="child" data-parent-id="{{ row.record.id }}"> + <td colspan="{{ table.columns|length }}"> + <table> + <tr> + <th>Applicant</th> + <th>Last updated</th> + <th>Next deadline</th> + <th>Reviewers / Outcomes</th> + </tr> + <tr> + <td>{{ submission.full_name }}</td> + <td> + <strong>by {{ row.cells.last_update.user }}</strong><br/> + {{ row.cells.last_update.timestamp|date:"m.d.y \a\t H:i" }} + </td> + <td></td> + <td></td> + </tr> + </table> + </td> </tr> {% endwith %} {% if row.record.previous %} {# we have a linked application #} {# re-render the header row #} - <tr class="child"> - {% for column in row.table.columns %} - <th>{{ column.header }}</th> - {% endfor %} + <tr class="child" data-parent-id="{{ row.record.id }}"> + <td colspan="{{ table.columns|length }}"> + <table> + <tr> + {% for column in row.table.columns %} + {% if forloop.first %} + <th>Linked {{ row.record.previous.stage }}</th> + {% else %} + <th>{{ column.header }}</th> + {% endif %} + {% endfor %} + </tr> + + {# mutate the row to render the data for the child row #} + {% with row=row|row_from_record:row.record.previous %} + {{ block.super }} + {% endwith %} + </table> + </td> </tr> - {# mutate the row to render the data for the child row #} - {% with row=row|row_from_record:row.record.previous %} - {{ block.super }} - {% endwith %} {% endif %} {% endblock %} -- GitLab