statistics: apply the selected status filter (#7060)

This commit is contained in:
Frédéric Péters 2015-04-28 15:41:20 +02:00
parent a8b3708e12
commit 6bad90e7f7
2 changed files with 64 additions and 3 deletions

View File

@ -239,6 +239,57 @@ def test_backoffice_statistics(pub):
resp = resp.forms[0].submit()
assert 'Total number of records: 0' in resp.body
def test_backoffice_statistics_status_filter(pub):
create_superuser(pub)
create_environment()
app = login(get_app(pub))
resp = app.get('/backoffice/form-title/')
resp = resp.click('Statistics')
assert 'filter' not in resp.forms[0].fields # status is not displayed by default
# add 'status' as a filter
resp.forms[0]['filter-status'].checked = True
resp = resp.forms[0].submit()
assert 'filter' in resp.forms[0].fields
assert resp.forms[0]['filter'].value == 'all'
resp.forms[0]['filter'].value = 'pending'
resp = resp.forms[0].submit()
assert 'Total number of records: 17' in resp.body
resp.forms[0]['filter'].value = 'done'
resp = resp.forms[0].submit()
assert 'Total number of records: 33' in resp.body
resp.forms[0]['filter'].value = 'rejected'
resp = resp.forms[0].submit()
assert 'Total number of records: 0' in resp.body
resp.forms[0]['filter'].value = 'all'
resp = resp.forms[0].submit()
assert 'Total number of records: 50' in resp.body
def test_backoffice_statistics_status_select(pub):
create_superuser(pub)
create_environment()
app = login(get_app(pub))
resp = app.get('/backoffice/form-title/')
resp = resp.click('Statistics')
resp.forms[0]['filter-2'].checked = True
resp = resp.forms[0].submit()
resp.forms[0]['filter-2-value'].value = 'bar'
resp = resp.forms[0].submit()
assert 'Total number of records: 13' in resp.body
resp.forms[0]['filter-2-value'].value = 'baz'
resp = resp.forms[0].submit()
assert 'Total number of records: 24' in resp.body
resp.forms[0]['filter-2-value'].value = 'foo'
resp = resp.forms[0].submit()
assert 'Total number of records: 13' in resp.body
def test_backoffice_handling(pub):
create_superuser(pub)
create_environment()

View File

@ -33,7 +33,7 @@ from qommon import errors
from qommon import ods
from qommon.form import *
from qommon.admin.menu import is_accessible
from qommon.storage import Equal, NotEqual, LessOrEqual, GreaterOrEqual
from qommon.storage import Equal, NotEqual, LessOrEqual, GreaterOrEqual, Or
from wcs.forms.common import FormStatusPage
@ -1112,13 +1112,23 @@ class FormPage(Directory):
r = TemplateIO(html=True)
get_response().breadcrumb.append( ('stats', _('Statistics')) )
selected_filter = self.get_filter_from_query()
selected_filter = self.get_filter_from_query(default='all')
criterias = self.get_criterias_from_query()
get_response().filter['sidebar'] = self.get_formdata_sidebar() + \
self.get_stats_sidebar(selected_filter)
do_graphs = get_publisher().is_using_postgresql()
if selected_filter and selected_filter != 'all':
if selected_filter == 'pending':
applied_filters = ['wf-%s' % x.id for x in
self.formdef.workflow.get_not_endpoint_status()]
elif selected_filter == 'done':
applied_filters = ['wf-%s' % x.id for x in
self.formdef.workflow.get_endpoint_status()]
else:
applied_filters = ['wf-%s' % selected_filter]
criterias.append(Or([Equal('status', x) for x in applied_filters]))
values = self.formdef.data_class().select(criterias)
if get_publisher().is_using_postgresql():
# load all evolutions in a single batch, to avoid as many query as