conditions: adapt encoding of validation errors (#36515)

This commit is contained in:
Frédéric Péters 2019-11-15 15:10:45 +01:00
parent 728f4c4bf4
commit 2268d53de0
1 changed files with 4 additions and 4 deletions

View File

@ -18,9 +18,9 @@ import sys
from quixote import get_publisher
from django.template import Context, Template, TemplateSyntaxError
from django.utils.encoding import force_text
from .qommon import _, get_logger
from .qommon.misc import site_encode
from .qommon import _, get_logger, force_str
class ValidationError(ValueError):
@ -90,11 +90,11 @@ class Condition(object):
try:
compile(self.value, '<string>', 'eval')
except (SyntaxError, TypeError) as e:
raise ValidationError(_('syntax error: %s') % site_encode(e))
raise ValidationError(_('syntax error: %s') % force_str(force_text(e)))
def validate_django(self):
try:
Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % (
get_publisher().get_default_templatetags_libraries(), self.value))
except TemplateSyntaxError as e:
raise ValidationError(_('syntax error: %s') % site_encode(e))
raise ValidationError(_('syntax error: %s') % force_str(force_text(e)))