backoffice: fix error count displayed (#55810)

This commit is contained in:
Lauréline Guérin 2021-07-27 14:34:08 +02:00
parent a0ba32d37a
commit 5e83d9ebcb
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 12 additions and 12 deletions

View File

@ -136,6 +136,8 @@ def test_listing_paginations(pub):
assert resp.text.count('Logged Error n°') == 17
# formdef errors
resp = app.get('/backoffice/forms/%s/' % formdef.id)
assert '21 errors' in resp
resp = app.get('/backoffice/forms/%s/logged-errors/' % formdef.id)
assert '1-20/21' in resp.text
assert resp.text.count('FormDef Workflow Logged Error n°') == 20
@ -144,6 +146,8 @@ def test_listing_paginations(pub):
assert resp.text.count('FormDef Workflow Logged Error n°') == 1
# carddef errors
resp = app.get('/backoffice/cards/%s/' % carddef.id)
assert '21 errors' in resp
resp = app.get('/backoffice/cards/%s/logged-errors/' % carddef.id)
assert '1-20/21' in resp.text
assert resp.text.count('CardDef Workflow Logged Error n°') == 20
@ -152,6 +156,8 @@ def test_listing_paginations(pub):
assert resp.text.count('CardDef Workflow Logged Error n°') == 1
# workflows errors
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
assert '63 errors' in resp
resp = app.get('/backoffice/workflows/%s/logged-errors/' % workflow.id)
assert '1-20/63' in resp.text
assert resp.text.count('Workflow Logged Error n°') == 20

View File

@ -110,9 +110,7 @@ class LoggedErrorsDirectory(Directory):
_q_exports = ['']
@classmethod
def get_errors(
cls, offset, limit, formdef_class=None, formdef_id=None, workflow_id=None, with_total=False
):
def get_errors(cls, offset, limit, formdef_class=None, formdef_id=None, workflow_id=None):
errors = []
if not get_publisher().loggederror_class:
return errors, 0
@ -141,19 +139,16 @@ class LoggedErrorsDirectory(Directory):
clauses.append(NotNull('formdef_class'))
errors = get_publisher().loggederror_class.select(clause=clauses, **select_kwargs)
count = 0
if with_total:
count = get_publisher().loggederror_class.count(clauses)
count = get_publisher().loggederror_class.count(clauses)
return list(errors), count
@classmethod
def errors_block(cls, formdef_class=None, formdef_id=None, workflow_id=None):
# select 3 + 1 last errors
errors = cls.get_errors(
errors, total = cls.get_errors(
offset=0, limit=4, formdef_class=formdef_class, formdef_id=formdef_id, workflow_id=workflow_id
)[0]
)
if not errors:
return ''
@ -161,8 +156,8 @@ class LoggedErrorsDirectory(Directory):
r += htmltext('<div class="bo-block logged-errors">')
r += (
htmltext('<h3><a href="logged-errors/">%s</a></h3>')
% ngettext('%(count)d error', '%(count)d errors', len(errors))
% {'count': len(errors)}
% ngettext('%(count)d error', '%(count)d errors', total)
% {'count': total}
)
r += htmltext('<ul>')
for error in errors[:3]:
@ -208,7 +203,6 @@ class LoggedErrorsDirectory(Directory):
formdef_class=self.formdef_class,
formdef_id=self.formdef_id,
workflow_id=self.workflow_id,
with_total=True,
)
links = ''
if get_publisher().is_using_postgresql():