0001-general-load-some-templatetags-libraries-by-default-.patch
tests/templates/qommon/forms/widgets/select--test.html | ||
---|---|---|
1 | 1 |
{% extends "qommon/forms/widget.html" %} |
2 |
{% load qommon %} |
|
3 | 2 |
{% block widget-control %} |
4 | 3 |
<!-- TEST TEMPLATE --> |
5 | 4 |
<!-- backoffice: {{ request.quixote_request.is_in_backoffice|pprint }} --> |
tests/test_templates.py | ||
---|---|---|
58 | 58 |
tmpl = Template('[if-any foo][foo][endif]') |
59 | 59 |
assert tmpl.render({'foo': 'bar'}) == '[if-any foo][foo][endif]' |
60 | 60 | |
61 |
def test_template_templatetag(): |
|
62 |
# check qommon templatetags are always loaded |
|
63 |
tmpl = Template('{{ date|parse_datetime|date:"Y" }}') |
|
64 |
assert tmpl.render({'date': '2018-06-06'}) == '2018' |
|
65 | ||
66 |
# check other templatetags can be loaded |
|
67 |
tmpl = Template('{% load i18n %}{% trans "hello" %}') |
|
68 |
assert tmpl.render() == 'hello' |
|
61 | 69 | |
62 | 70 |
def test_template_encoding(): |
63 | 71 |
# django |
... | ... | |
84 | 92 | |
85 | 93 | |
86 | 94 |
def test_datetime_templatetags(): |
87 |
tmpl = Template('{% load qommon %}{{ plop|parse_datetime|date:"d i" }}')
|
|
95 |
tmpl = Template('{{ plop|parse_datetime|date:"d i" }}') |
|
88 | 96 |
assert tmpl.render({'plop': '2017-12-21 10:32'}) == '21 32' |
89 | 97 |
assert tmpl.render({'plop': '2017-12-21 10:32:42'}) == '21 32' |
90 | 98 |
assert tmpl.render({'plop': '21/12/2017 10:32'}) == '21 32' |
... | ... | |
92 | 100 |
assert tmpl.render({'plop': '21/12/2017 10h32'}) == '21 32' |
93 | 101 |
assert tmpl.render({'plop': 'x'}) == '' |
94 | 102 | |
95 |
tmpl = Template('{% load qommon %}{{ plop|parse_date|date:"d" }}')
|
|
103 |
tmpl = Template('{{ plop|parse_date|date:"d" }}') |
|
96 | 104 |
assert tmpl.render({'plop': '2017-12-21'}) == '21' |
97 | 105 |
assert tmpl.render({'plop': '21/12/2017'}) == '21' |
98 | 106 |
assert tmpl.render({'plop': 'x'}) == '' |
99 | 107 | |
100 |
tmpl = Template('{% load qommon %}{{ plop|parse_time|date:"H i" }}')
|
|
108 |
tmpl = Template('{{ plop|parse_time|date:"H i" }}') |
|
101 | 109 |
assert tmpl.render({'plop': '10:32'}) == '10 32' |
102 | 110 |
assert tmpl.render({'plop': 'x'}) == '' |
wcs/conditions.py | ||
---|---|---|
61 | 61 |
return eval(self.value, global_variables, local_variables) |
62 | 62 | |
63 | 63 |
def evaluate_django(self, local_variables): |
64 |
template = Template('{%% load qommon %%}{%% if %s %%}OK{%% endif %%}' % self.value) |
|
64 |
template = Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % ( |
|
65 |
get_publisher().get_default_templatetags_libraries(), self.value)) |
|
65 | 66 |
context = Context(local_variables) |
66 | 67 |
return template.render(context) == 'OK' |
67 | 68 | |
... | ... | |
82 | 83 | |
83 | 84 |
def validate_django(self): |
84 | 85 |
try: |
85 |
Template('{%% load qommon %%}{%% if %s %%}OK{%% endif %%}' % self.value) |
|
86 |
Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % ( |
|
87 |
get_publisher().get_default_templatetags_libraries(), self.value)) |
|
86 | 88 |
except TemplateSyntaxError as e: |
87 | 89 |
raise ValidationError(_('syntax error: %s') % e) |
wcs/qommon/publisher.py | ||
---|---|---|
945 | 945 |
default_position = '50.84;4.36' |
946 | 946 |
return default_position |
947 | 947 | |
948 |
def get_default_templatetags_libraries(self): |
|
949 |
libraries = self.get_site_option('default_templatetags_libraries') or '' |
|
950 |
return 'qommon %s' % libraries |
|
951 | ||
948 | 952 |
def get_map_attributes(self): |
949 | 953 |
attrs = {} |
950 | 954 |
attrs['data-def-lat'], attrs['data-def-lng'] = self.get_default_position().split(';') |
wcs/qommon/template.py | ||
---|---|---|
465 | 465 |
self.render = self.django_render |
466 | 466 |
if autoescape is False: |
467 | 467 |
value = '{%% autoescape off %%}%s{%% endautoescape %%}' % value |
468 |
value = '{%% load %s %%}%s' % ( |
|
469 |
get_publisher().get_default_templatetags_libraries(), value) |
|
468 | 470 |
try: |
469 | 471 |
self.template = engines['django'].from_string(value) |
470 | 472 |
except DjangoTemplateSyntaxError as e: |
wcs/qommon/templates/qommon/forms/widget.html | ||
---|---|---|
1 |
{% load qommon %} |
|
2 | 1 |
<div class="widget {{widget.class_name}} {{widget.extra_css_class}} |
3 | 2 |
{% if widget.readonly %}widget-readonly{% endif %} |
4 | 3 |
{% if widget.get_error %}widget-with-error{% endif %} |
5 |
- |