From a258c1b049a26f4cea8bfeddc35a24f30e9853b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 5 Nov 2015 15:22:45 +0100 Subject: [PATCH] backoffice: display current user forms in the sidebar (#8879) --- tests/test_backoffice_pages.py | 55 ++++++++++++++++++ wcs/backoffice/management.py | 112 +++++++++++++++++++++++++++--------- wcs/categories.py | 6 ++ wcs/qommon/static/css/dc2/admin.css | 9 +++ 4 files changed, 155 insertions(+), 27 deletions(-) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index c7393e7..4c87548 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -15,6 +15,7 @@ from wcs.roles import Role from wcs.workflows import (Workflow, CommentableWorkflowStatusItem, ChoiceWorkflowStatusItem) from wcs.wf.wscall import WebserviceCallStatusItem +from wcs.categories import Category from wcs.formdef import FormDef from wcs import fields @@ -65,6 +66,7 @@ def create_superuser(pub): create_user(pub, is_admin=True) def create_environment(pub, set_receiver=True): + Category.wipe() FormDef.wipe() formdef = FormDef() formdef.name = 'form title' @@ -877,3 +879,56 @@ def test_tracking_code_access(pub): assert resp.location == 'http://example.net/backoffice/management/listing' resp = resp.follow() assert 'No such code' in resp.body + +def test_backoffice_sidebar_user_context(pub): + if not pub.is_using_postgresql(): + pytest.skip('this requires SQL') + return + + user = create_user(pub) + create_environment(pub) + form_class = FormDef.get_by_urlname('form-title').data_class() + number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0] + app = login(get_app(pub)) + resp = app.get('/backoffice/management/form-title/') + assert re.findall('', resp.body, re.DOTALL)[0].count('cat1<' in resp.body + assert '>Misc<' in resp.body + assert resp.body.index('>Misc<') < resp.body.index('>cat1<') diff --git a/wcs/backoffice/management.py b/wcs/backoffice/management.py index a36b132..f8da898 100644 --- a/wcs/backoffice/management.py +++ b/wcs/backoffice/management.py @@ -1251,35 +1251,93 @@ class FormBackOfficeStatusPage(FormStatusPage): def get_extra_context_bar(self): formdata = self.filled - if not formdata.submission_context: - return '' r = TemplateIO(html=True) - extra_context = formdata.submission_context or {} - r += htmltext('
') - if extra_context.get('channel'): - channel_labels = { - 'mail': _('Mail'), - } - r += htmltext('

%s

') % '%s: %s' % ( - _('Channel'), channel_labels.get(extra_context.get('channel'), '?')) - if extra_context.get('thumbnail_url'): - r += htmltext('

' - ) % extra_context.get('thumbnail_url') - if extra_context.get('mail_url'): - r += htmltext('

%s

') % ( - extra_context.get('mail_url'), _('Open')) - if extra_context.get('user_id'): - r += htmltext('

%s

') % _('Associated User') - r += htmltext('

%s

') % get_publisher().user_class.get( - extra_context.get('user_id')).display_name - if extra_context.get('comments'): - r += htmltext('

%s

') % _('Comments') - r += htmltext('

%s

') % extra_context.get('comments') - if extra_context.get('summary_url'): - r += htmltext('
' % - (extra_context.get('summary_url'))) - r += htmltext('
') + if formdata.submission_context: + extra_context = formdata.submission_context or {} + r += htmltext('
') + if extra_context.get('channel'): + channel_labels = { + 'mail': _('Mail'), + } + r += htmltext('

%s

') % '%s: %s' % ( + _('Channel'), channel_labels.get(extra_context.get('channel'), '?')) + if extra_context.get('thumbnail_url'): + r += htmltext('

' + ) % extra_context.get('thumbnail_url') + if extra_context.get('mail_url'): + r += htmltext('

%s

') % ( + extra_context.get('mail_url'), _('Open')) + if extra_context.get('user_id'): + r += htmltext('

%s

') % _('Associated User') + r += htmltext('

%s

') % get_publisher().user_class.get( + extra_context.get('user_id')).display_name + if extra_context.get('comments'): + r += htmltext('

%s

') % _('Comments') + r += htmltext('

%s

') % extra_context.get('comments') + if extra_context.get('summary_url'): + r += htmltext('
' % + (extra_context.get('summary_url'))) + r += htmltext('
') + + if formdata.user_id and get_publisher().is_using_postgresql(): + # display list of open formdata for the same user + user_roles = [logged_users_role().id] + (get_request().user.roles or []) + criterias = [Equal('is_at_endpoint', False), + Equal('user_id', str(formdata.user_id)), + Intersects('concerned_roles_array', user_roles), + ] + from wcs import sql + formdatas = sql.AnyFormData.select(criterias, order_by='-receipt_time', limit=50) + + # exclude currently displayed formdate from list + formdatas = [x for x in formdatas if not ( + str(x.formdef_id) == str(self.formdef.id) and str(x.id) == str(formdata.id))] + + if formdatas: + r += htmltext('
') + r += htmltext('

%s

') % _('Other Pending Forms') + categories = {} + formdata_by_category = {} + for formdata in formdatas: + if not formdata.formdef.category_id in categories: + categories[formdata.formdef.category_id] = formdata.formdef.category + formdata_by_category[formdata.formdef.category_id] = [] + formdata_by_category[formdata.formdef.category_id].append(formdata) + cats = categories.values() + Category.sort_by_position(cats) + if self.formdef.category_id in categories: + # move current category to the top + cats.remove(categories[self.formdef.category_id]) + cats.insert(0, categories[self.formdef.category_id]) + for cat in cats: + if len(cats) > 1: + if cat is None: + r += htmltext('

%s

') % _('Misc') + cat_formdatas = formdata_by_category[None] + else: + r += htmltext('

%s

') % cat.name + cat_formdatas = formdata_by_category[cat.id] + else: + cat_formdatas = formdatas + r += htmltext('
    ') + for formdata in cat_formdatas: + status = formdata.get_status() + if status: + status_label = status.name + else: + status_label = _('Unknown') + submit_date = misc.strftime.strftime( + misc.date_format(), formdata.receipt_time) + r += htmltext('
  • %s, ' + '%s ' + '(%s)' % ( + formdata.get_url(backoffice=True), + formdata.formdef.name, + submit_date, status_label)) + r += htmltext('
') + r += htmltext('
') + return r.getvalue() diff --git a/wcs/categories.py b/wcs/categories.py index a1f7373..00fa6e5 100644 --- a/wcs/categories.py +++ b/wcs/categories.py @@ -65,6 +65,12 @@ class Category(XmlStorableObject): def sort_by_position(cls, categories): def cmp_position(x, y): + if x is None and x is None: + return 0 + if y is None: + return -1 + if x is None: + return 1 if x.position == y.position: return 0 if x.position is None: diff --git a/wcs/qommon/static/css/dc2/admin.css b/wcs/qommon/static/css/dc2/admin.css index 4a9260d..9b9389c 100644 --- a/wcs/qommon/static/css/dc2/admin.css +++ b/wcs/qommon/static/css/dc2/admin.css @@ -1109,5 +1109,14 @@ div#tracking-code button { div.bo-block.important { background: #fd6; border: 1px solid #ffae15; +} +div.other-pending-forms ul { + margin-left: 0; + padding-left: 1.5em; +} + +div.other-pending-forms span.datetime, +div.other-pending-forms span.status { + font-size: 80%; } -- 2.6.2