backoffice: add a hint when a template is used as condition in inspect (#31413) #831
|
@ -429,6 +429,15 @@ def test_inspect_page(pub, local_user):
|
|||
assert resp.pyquery('#test-tool-result p:last-child').text() == 'Invalid filter "not a field"'
|
||||
assert pub.loggederror_class.count() == 0
|
||||
|
||||
# check there's a custom hint when a template is used as condition
|
||||
resp.form['test_mode'] = 'django-condition'
|
||||
resp.form['django-condition'] = '{% if True %}hello{% endif %}'
|
||||
resp = resp.form.submit()
|
||||
assert (
|
||||
resp.pyquery('#test-tool-result p.hint').text()
|
||||
== 'This tool expects a condition, not a complete template.'
|
||||
)
|
||||
|
||||
|
||||
def test_inspect_page_with_related_objects(pub):
|
||||
user = create_user(pub, is_admin=True)
|
||||
|
|
|
@ -85,7 +85,7 @@ from ..qommon.form import (
|
|||
)
|
||||
from ..qommon.misc import ellipsize, get_type_name, is_ascii_digit
|
||||
from ..qommon.substitution import CompatibilityNamesDict, SubtreeVar
|
||||
from ..qommon.template import Template
|
||||
from ..qommon.template import DjangoTemplateSyntaxError, Template
|
||||
from ..qommon.upload_storage import PicklableUpload
|
||||
from .submission import FormFillPage
|
||||
|
||||
|
@ -3744,8 +3744,9 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
# show test result
|
||||
test_mode = form.get_widget('test_mode').parse()
|
||||
if test_mode in ('django-condition', 'python-condition'):
|
||||
condition_value = form.get_widget(test_mode).parse()
|
||||
condition = Condition(
|
||||
{'value': form.get_widget(test_mode).parse(), 'type': test_mode.split('-')[0]},
|
||||
{'value': condition_value, 'type': test_mode.split('-')[0]},
|
||||
record_errors=False,
|
||||
)
|
||||
try:
|
||||
|
@ -3754,6 +3755,12 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
r += htmltext('<div class="errornotice">')
|
||||
r += htmltext('<p>%s</p>') % _('Failed to evaluate condition')
|
||||
r += self.get_inspect_error_message(exception)
|
||||
if isinstance(exception, DjangoTemplateSyntaxError) and Template.is_template_string(
|
||||
condition_value, ezt_support=False
|
||||
):
|
||||
r += htmltext('<p class="hint">%s</p>') % _(
|
||||
'This tool expects a condition, not a complete template.'
|
||||
)
|
||||
r += htmltext('</div>')
|
||||
else:
|
||||
r += htmltext('<div class="test-tool-result infonotice">')
|
||||
|
|
Loading…
Reference in New Issue