0001-general-load-some-templatetags-libraries-by-default-.patch
tests/test_templates.py | ||
---|---|---|
84 | 84 | |
85 | 85 | |
86 | 86 |
def test_datetime_templatetags(): |
87 |
tmpl = Template('{% load qommon %}{{ plop|parse_datetime|date:"d i" }}')
|
|
87 |
tmpl = Template('{{ plop|parse_datetime|date:"d i" }}') |
|
88 | 88 |
assert tmpl.render({'plop': '2017-12-21 10:32'}) == '21 32' |
89 | 89 |
assert tmpl.render({'plop': '2017-12-21 10:32:42'}) == '21 32' |
90 | 90 |
assert tmpl.render({'plop': '21/12/2017 10:32'}) == '21 32' |
... | ... | |
92 | 92 |
assert tmpl.render({'plop': '21/12/2017 10h32'}) == '21 32' |
93 | 93 |
assert tmpl.render({'plop': 'x'}) == '' |
94 | 94 | |
95 |
tmpl = Template('{% load qommon %}{{ plop|parse_date|date:"d" }}')
|
|
95 |
tmpl = Template('{{ plop|parse_date|date:"d" }}') |
|
96 | 96 |
assert tmpl.render({'plop': '2017-12-21'}) == '21' |
97 | 97 |
assert tmpl.render({'plop': '21/12/2017'}) == '21' |
98 | 98 |
assert tmpl.render({'plop': 'x'}) == '' |
99 | 99 | |
100 |
tmpl = Template('{% load qommon %}{{ plop|parse_time|date:"H i" }}')
|
|
100 |
tmpl = Template('{{ plop|parse_time|date:"H i" }}') |
|
101 | 101 |
assert tmpl.render({'plop': '10:32'}) == '10 32' |
102 | 102 |
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 |
- |