From 749121cc2daddd0d5c69a103a2dfe68760dc3629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 8 Nov 2015 21:49:07 +0100 Subject: [PATCH] backoffice: add channel and modification time columns to global listing (#8918) --- tests/test_backoffice_pages.py | 21 +++++++++++++++++++++ wcs/backoffice/management.py | 13 +++++++++++-- wcs/formdata.py | 7 ++++++- wcs/sql.py | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index 4730088..8c96943 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -4,6 +4,7 @@ import os import re import shutil import StringIO +import time import pytest @@ -920,6 +921,26 @@ def test_global_listing(pub): assert 'http://example.net/backoffice/management/other-form/' in resp.body assert not 'http://example.net/backoffice/management/form-title/' in resp.body + formdef = FormDef.get_by_urlname('form-title') + last_update_time = formdef.data_class().select()[0].last_update_time + # check created and last modified columns + assert '>2014-01-01 00:00<' in resp.body + assert time.strftime('>%Y-%m-%d', last_update_time) in resp.body + + # check a Channel column is added when welco is available + assert not 'Channel' in resp.body + + if not pub.site_options.has_section('variables'): + pub.site_options.add_section('variables') + pub.site_options.set('variables', 'welco_url', 'xxx') + fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') + pub.site_options.write(fd) + fd.close() + + resp = app.get('/backoffice/management/listing') + assert 'Channel' in resp.body + assert '>Web<' in resp.body + def test_tracking_code_access(pub): create_user(pub) create_environment(pub, set_receiver=False) diff --git a/wcs/backoffice/management.py b/wcs/backoffice/management.py index a5ae881..ff97c31 100644 --- a/wcs/backoffice/management.py +++ b/wcs/backoffice/management.py @@ -337,12 +337,17 @@ class ManagementDirectory(Directory): total_count = sql.AnyFormData.count(criterias) formdatas = sql.AnyFormData.select(criterias, order_by='receipt_time', limit=limit, offset=offset) + include_submission_channel = bool( + get_publisher().get_site_option('welco_url', 'variables')) r = TemplateIO(html=True) r += htmltext('') r += htmltext('') + if include_submission_channel: + r += htmltext('') % _('Channel') r += htmltext('') % _('Form') - r += htmltext('') % _('Date') + r += htmltext('') % _('Created') + r += htmltext('') % _('Last Modified') r += htmltext('') % _('User') r += htmltext('') % _('Status') r += htmltext('') @@ -355,16 +360,20 @@ class ManagementDirectory(Directory): formdata.formdef.workflow.id, formdata.status, formdata.get_url(backoffice=True))) + if include_submission_channel: + r += htmltext('') % formdata.get_submission_channel_label() r += htmltext('') % formdata.formdef.name r += htmltext('') % misc.localstrftime( formdata.receipt_time) + r += htmltext('') % misc.localstrftime( + formdata.last_update_time) try: value = get_publisher().user_class.get(formdata.user_id).display_name r += htmltext('') % value except: r += htmltext('') r += htmltext('') % formdata.get_status_label() - r += htmltext('') + r += htmltext('\n') if workflows: colours = [] diff --git a/wcs/formdata.py b/wcs/formdata.py index f6efee4..d938b16 100644 --- a/wcs/formdata.py +++ b/wcs/formdata.py @@ -556,12 +556,17 @@ class FormData(StorableObject): actions_roles = property(get_actions_roles) def get_last_update_time(self): + if hasattr(self, '_last_update_time'): + return self._last_update_time if self.evolution and self.evolution[-1].time: return self.evolution[-1].time else: return self.receipt_time - last_update_time = property(get_last_update_time) + def set_last_update_time(self, value): + self._last_update_time = value + + last_update_time = property(get_last_update_time, set_last_update_time) def anonymise(self): for field in self.formdef.fields: diff --git a/wcs/sql.py b/wcs/sql.py index e331bbf..db08bd7 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -1535,6 +1535,7 @@ class AnyFormData(SqlMixin): fake_formdef = FormDef() common_fields = get_view_fields(fake_formdef) cls.__table_static_fields = [(x[1], x[0]) for x in common_fields] + cls.__table_static_fields.append(('last_update_time', 'timestamp')) return cls.__table_static_fields @classmethod -- 2.6.2
%s%s%s%s%s%s%s
%s%s%s%s%s-%s