Projet

Général

Profil

0001-misc-set-qommon-l10n-as-builtin-templatetags-in-sett.patch

Frédéric Péters, 17 février 2020 20:00

Télécharger (4,96 ko)

Voir les différences:

Subject: [PATCH] misc: set qommon/l10n as builtin templatetags in settings
 (#37275)

 wcs/conditions.py                             | 6 ++----
 wcs/qommon/publisher.py                       | 4 ----
 wcs/qommon/template.py                        | 2 --
 wcs/qommon/templates/qommon/forms/widget.html | 1 -
 wcs/settings.py                               | 4 ++++
 wcs/templates/wcs/backoffice.html             | 1 -
 wcs/templates/wcs/formdata_filling.html       | 2 +-
 wcs/templates/wcs/formdata_validation.html    | 1 -
 8 files changed, 7 insertions(+), 14 deletions(-)
wcs/conditions.py
70 70
        return eval(self.value, global_variables, local_variables)
71 71

  
72 72
    def evaluate_django(self, local_variables):
73
        template = Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % (
74
            get_publisher().get_default_templatetags_libraries(), self.value))
73
        template = Template('{%% if %s %%}OK{%% endif %%}' % self.value)
75 74
        context = Context(local_variables)
76 75
        return template.render(context) == 'OK'
77 76

  
......
92 91

  
93 92
    def validate_django(self):
94 93
        try:
95
            Template('{%% load %s %%}{%% if %s %%}OK{%% endif %%}' % (
96
                get_publisher().get_default_templatetags_libraries(), self.value))
94
            Template('{%% if %s %%}OK{%% endif %%}' % self.value)
97 95
        except TemplateSyntaxError as e:
98 96
            raise ValidationError(_('syntax error: %s') % force_str(force_text(e)))
wcs/qommon/publisher.py
843 843
            default_position = '50.84;4.36'
844 844
        return default_position
845 845

  
846
    def get_default_templatetags_libraries(self):
847
        libraries = self.get_site_option('default_templatetags_libraries') or ''
848
        return 'qommon l10n %s' % libraries
849

  
850 846
    def get_map_attributes(self):
851 847
        attrs = {}
852 848
        attrs['data-def-lat'], attrs['data-def-lng'] = self.get_default_position().split(';')
wcs/qommon/template.py
471 471
            self.render = self.django_render
472 472
            if autoescape is False:
473 473
                value = '{%% autoescape off %%}%s{%% endautoescape %%}' % value
474
            value = '{%% load %s %%}%s' % (
475
                    get_publisher().get_default_templatetags_libraries(), value)
476 474
            try:
477 475
                self.template = engines['django'].from_string(value)
478 476
            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 %}
wcs/settings.py
104 104
                'django.template.loaders.filesystem.Loader',
105 105
                'django.template.loaders.app_directories.Loader',
106 106
            ],
107
            'builtins': [
108
                'wcs.qommon.templatetags.qommon',
109
                'django.templatetags.l10n',
110
            ],
107 111
        },
108 112
    },
109 113
]
wcs/templates/wcs/backoffice.html
1 1
{% extends "gadjo/base.html" %}
2
{% load qommon %}
3 2

  
4 3
{% block page-title %}{{ page_title }}{% endblock %}
5 4
{% block site-title %}{{ site_name }}{% endblock %}
wcs/templates/wcs/formdata_filling.html
1 1
{% extends template_base %}
2
{% load i18n qommon %}
2
{% load i18n %}
3 3

  
4 4
{% block body %}
5 5

  
wcs/templates/wcs/formdata_validation.html
1 1
{% extends template_base %}
2
{% load qommon %}
3 2

  
4 3
{% block body %}
5 4
<div class="form-validation">
6
-