From b41bbd164c67ff9bf0543770e8f551de8e85140f Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Mon, 27 Mar 2017 15:34:06 +0200 Subject: [PATCH] backoffice: display message on global statistics when there are no formdefs (#15644) --- tests/test_backoffice_pages.py | 16 ++++++++++++++++ wcs/backoffice/management.py | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py index bc3c2391..0e92e0d3 100644 --- a/tests/test_backoffice_pages.py +++ b/tests/test_backoffice_pages.py @@ -802,6 +802,22 @@ def test_backoffice_statistics(pub): assert '

Filters

' in resp.body assert 'End: 2013-01-01' in resp.body +def test_backoffice_statistics_with_no_formdefs(pub): + create_user(pub) + create_environment(pub) + FormDef.wipe() + if pub.is_using_postgresql(): + from wcs.sql import get_connection_and_cursor, drop_global_views + conn, cur = get_connection_and_cursor() + drop_global_views(conn, cur) + conn.commit() + cur.close() + + app = login(get_app(pub)) + resp = app.get('/backoffice/management/').follow() + resp = resp.click('Global statistics') + assert 'This site is currently empty.' in resp.body + def test_backoffice_statistics_status_filter(pub): create_superuser(pub) create_environment(pub) diff --git a/wcs/backoffice/management.py b/wcs/backoffice/management.py index 48b6a0f4..441445bf 100644 --- a/wcs/backoffice/management.py +++ b/wcs/backoffice/management.py @@ -606,6 +606,17 @@ class ManagementDirectory(Directory): return r.getvalue() def statistics(self): + if FormDef.count() == 0: + r = TemplateIO(html=True) + r += htmltext('
') + r += htmltext('

%s

') % _('Global statistics') + r += htmltext('
') + r += htmltext('
') + r += htmltext('

%s

') % _( + 'This site is currently empty. It is required to first add forms.') + r += htmltext('
') + return r.getvalue() + html_top('management', _('Global statistics')) get_response().breadcrumb.append(('statistics', _('Global statistics'))) get_response().filter['sidebar'] = self.get_stats_sidebar() -- 2.11.0