From 18a0b6b147a605c28245176f1dd56a9979e2e8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 28 Jan 2023 20:14:06 +0100 Subject: [PATCH] misc: use native templates for form pages (#73956) --- data/themes/django/templates/wcs/base.html | 34 --------------- data/themes/django/templates/wcs/home.html | 20 --------- wcs/backoffice/submission.py | 14 +++---- wcs/context_processors.py | 5 ++- wcs/forms/root.py | 16 ++++++-- wcs/qommon/template.py | 3 +- wcs/templates/wcs/backoffice-legacy.html | 1 + wcs/templates/wcs/backoffice.html | 3 ++ .../wcs/backoffice/formdata_filling.html | 9 ++++ .../wcs/backoffice/formdata_validation.html | 9 ++++ wcs/templates/wcs/base.html | 41 ++++++++++++++++++- wcs/templates/wcs/formdata_filling.html | 9 ++-- wcs/templates/wcs/formdata_popup_filling.html | 2 + wcs/templates/wcs/formdata_validation.html | 5 ++- wcs/views.py | 1 + 15 files changed, 96 insertions(+), 76 deletions(-) delete mode 100644 data/themes/django/templates/wcs/base.html delete mode 100644 data/themes/django/templates/wcs/home.html create mode 100644 wcs/templates/wcs/backoffice/formdata_filling.html create mode 100644 wcs/templates/wcs/backoffice/formdata_validation.html diff --git a/data/themes/django/templates/wcs/base.html b/data/themes/django/templates/wcs/base.html deleted file mode 100644 index 2b3db1b4e..000000000 --- a/data/themes/django/templates/wcs/base.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - {% block page-title %}{{ page_title }}{% endblock %} - - {{ script|safe }} - {% block extrascripts %} - {% endblock %} - - -
-
-
- {% block header %} -

{% if title %}{{ title }}{% else %}{{ site_name }}{% endif %}

- {% endblock %} -
-
- {% block content %} - {{ prelude }} - - {% if breadcrumb %} - - {% endif %} - - {% block body %} - {{ body|safe }} - {% endblock %} - - {% endblock %} -
- - - diff --git a/data/themes/django/templates/wcs/home.html b/data/themes/django/templates/wcs/home.html deleted file mode 100644 index 9611fd9da..000000000 --- a/data/themes/django/templates/wcs/home.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "base.html"%} - -{% block body %} - -
-

HELLO WORLD

- - {% regroup forms by category as category_list %} - {% for category in category_list %} - {% if category.grouper %}

{{ category.grouper }}

{% endif %} - - {% endfor %} - -
- -{% endblock %} diff --git a/wcs/backoffice/submission.py b/wcs/backoffice/submission.py index 00801ea89..ab0bb8253 100644 --- a/wcs/backoffice/submission.py +++ b/wcs/backoffice/submission.py @@ -104,9 +104,9 @@ class FormFillPage(PublicFormFillPage): ('go-to-backoffice', 'go_to_backoffice'), ] - filling_templates = ['wcs/formdata_filling.html'] + filling_templates = ['wcs/backoffice/formdata_filling.html'] popup_filling_templates = ['wcs/formdata_popup_filling.html'] - validation_templates = ['wcs/formdata_validation.html'] + validation_templates = ['wcs/backoffice/formdata_validation.html'] steps_templates = ['wcs/formdata_steps.html'] has_channel_support = True has_user_support = True @@ -211,6 +211,7 @@ class FormFillPage(PublicFormFillPage): return None def modify_filling_context(self, context, page, data): + context['sidebar'] = self.get_sidebar(data) if not self.formdef.only_allow_one: return try: @@ -223,6 +224,9 @@ class FormFillPage(PublicFormFillPage): data_class.count([StrictNotEqual('status', 'draft'), Equal('user_id', formdata.user_id)]) ) + def modify_validation_context(self, context, data): + context['sidebar'] = self.get_sidebar(data) + def get_sidebar(self, data): r = TemplateIO(html=True) @@ -329,8 +333,6 @@ class FormFillPage(PublicFormFillPage): def form_side(self, data=None, magictoken=None): r = TemplateIO(html=True) get_response().filter['sidebar'] = self.get_sidebar(data) - r += htmltext('
') - r += htmltext('

%s

') % self.formdef.name if not self.edit_mode and not getattr(self, 'is_popup', False): draft_formdata_id = data.get('draft_formdata_id') if draft_formdata_id: @@ -338,10 +340,6 @@ class FormFillPage(PublicFormFillPage): draft_formdata_id, _('Discard this form'), ) - r += htmltext('
') - r += htmltext('
') - r += self.step() - r += htmltext('
') return mark_safe(str(r.getvalue())) def submitted(self, form, *args): diff --git a/wcs/context_processors.py b/wcs/context_processors.py index 4f2267869..6d4505c06 100644 --- a/wcs/context_processors.py +++ b/wcs/context_processors.py @@ -28,7 +28,10 @@ def get_global_context(): def publisher(request): template_base = 'wcs/base.html' if request.path.startswith('/backoffice/'): - template_base = 'wcs/blank.html' + if getattr(request, 'is_django_native', False): + template_base = 'wcs/backoffice.html' + else: + template_base = 'wcs/blank.html' from wcs.qommon.admin.menu import get_vc_version diff --git a/wcs/forms/root.py b/wcs/forms/root.py index 7bbfaa17c..289cf84ec 100644 --- a/wcs/forms/root.py +++ b/wcs/forms/root.py @@ -697,7 +697,7 @@ class FormPage(FormdefDirectoryBase, FormTemplateMixin): 'view': self, 'page_no': self.get_current_page_no, 'formdef': LazyFormDef(self.formdef), - 'form_side': lambda: self.form_side(data=data, magictoken=magictoken), + 'form_side': self.form_side(data=data, magictoken=magictoken), 'steps': self.step, # legacy, used in some themes 'tracking_code_box': lambda: self.tracking_code_box(data, magictoken), @@ -716,7 +716,9 @@ class FormPage(FormdefDirectoryBase, FormTemplateMixin): context['form'] = form return template.QommonTemplateResponse( - templates=list(self.get_formdef_template_variants(self.filling_templates)), context=context + templates=list(self.get_formdef_template_variants(self.filling_templates)), + context=context, + is_django_native=True, ) def tracking_code_box(self, data, magictoken): @@ -1787,17 +1789,23 @@ class FormPage(FormdefDirectoryBase, FormTemplateMixin): context = { 'view': self, 'html_form': form, - 'form_side': lambda: self.form_side(data=data, magictoken=magictoken), + 'form_side': self.form_side(data=data, magictoken=magictoken), 'steps': self.step, # legacy, used in some themes 'tracking_code_box': lambda: self.tracking_code_box(data, magictoken), } context['form'] = form # legacy + self.modify_validation_context(context, data) return template.QommonTemplateResponse( - templates=list(self.get_formdef_template_variants(self.validation_templates)), context=context + templates=list(self.get_formdef_template_variants(self.validation_templates)), + context=context, + is_django_native=True, ) + def modify_validation_context(self, context, data): + pass + def get_url_with_query(self): query = get_request().get_query() url = self.formdef.get_url() diff --git a/wcs/qommon/template.py b/wcs/qommon/template.py index cfd14a720..07a9140be 100644 --- a/wcs/qommon/template.py +++ b/wcs/qommon/template.py @@ -147,7 +147,8 @@ def get_decorate_vars(body, response, generate_breadcrumb=True, **kwargs): user_info = kwargs.get('user_info') page_title = kwargs.get('title', '') subtitle = kwargs.get('subtitle') - sidebar = kwargs.get('sidebar') + if 'sidebar' in kwargs: + sidebar = kwargs.get('sidebar') css = root_url + get_publisher().qommon_static_dir + get_publisher().qommon_admin_css extra_head = get_publisher().get_site_option('backoffice_extra_head') app_label = get_publisher().get_site_option('app_label') or 'Publik' diff --git a/wcs/templates/wcs/backoffice-legacy.html b/wcs/templates/wcs/backoffice-legacy.html index 2116c27f9..6a3cb4705 100644 --- a/wcs/templates/wcs/backoffice-legacy.html +++ b/wcs/templates/wcs/backoffice-legacy.html @@ -1,6 +1,7 @@ {% extends "wcs/backoffice.html" %} {% block main-content %} + {{ form_side|default:"" }} {{ body|safe }} {% endblock %} diff --git a/wcs/templates/wcs/backoffice.html b/wcs/templates/wcs/backoffice.html index 46594e7cb..5db5c598f 100644 --- a/wcs/templates/wcs/backoffice.html +++ b/wcs/templates/wcs/backoffice.html @@ -39,11 +39,14 @@

{% block appbar-title %}{% endblock %}

{% block appbar-actions %}{% endblock %} + {% block appbar-bottom %}{% endblock %}
{% endblock %} {% block session-message %} {{session_message|safe}} {% endblock %} + {% block form-side %}{% endblock %} + {% block body %}{% endblock %} {% endblock %} {% endblock %} diff --git a/wcs/templates/wcs/backoffice/formdata_filling.html b/wcs/templates/wcs/backoffice/formdata_filling.html new file mode 100644 index 000000000..d934d784c --- /dev/null +++ b/wcs/templates/wcs/backoffice/formdata_filling.html @@ -0,0 +1,9 @@ +{% extends "wcs/formdata_filling.html" %} + +{% block appbar-title %}{{ view.formdef.name }}{% endblock %} +{% block form-side %}{% endblock %} + +{% block appbar-bottom %} + {{ form_side|default:"" }} +
{{ view.step }}
+{% endblock %} diff --git a/wcs/templates/wcs/backoffice/formdata_validation.html b/wcs/templates/wcs/backoffice/formdata_validation.html new file mode 100644 index 000000000..f10397c5c --- /dev/null +++ b/wcs/templates/wcs/backoffice/formdata_validation.html @@ -0,0 +1,9 @@ +{% extends "wcs/formdata_validation.html" %} + +{% block appbar-title %}{{ view.formdef.name }}{% endblock %} +{% block form-side %}{% endblock %} + +{% block appbar-bottom %} + {{ form_side|default:"" }} +
{{ view.step }}
+{% endblock %} diff --git a/wcs/templates/wcs/base.html b/wcs/templates/wcs/base.html index 47b555da3..63f409324 100644 --- a/wcs/templates/wcs/base.html +++ b/wcs/templates/wcs/base.html @@ -1,2 +1,39 @@ -{% block body %} -{% endblock %} + + + + {% block page-title %}{{ page_title }}{% endblock %} + + {{ script|safe }} + {% block extrascripts %} + {% endblock %} + + +
+
+
+ {% block header %} +

{% if title %}{{ title }}{% else %}{{ site_name }}{% endif %}

+ {% endblock %} +
+
+ {% block content %} + + {% if form_side %} +
{{ form_side|safe }}
+ {% endif %} + + {% if breadcrumb %} + + {% endif %} + + {{ publisher.get_request.session.display_message|safe }} + + {% block body %} + {{ body|safe }} + {% endblock %} + + {% endblock %} +
+ + + diff --git a/wcs/templates/wcs/formdata_filling.html b/wcs/templates/wcs/formdata_filling.html index a7afad3e8..7fc213315 100644 --- a/wcs/templates/wcs/formdata_filling.html +++ b/wcs/templates/wcs/formdata_filling.html @@ -1,12 +1,11 @@ {% extends template_base %} {% load i18n %} -{% block body %} +{% block form-side %} + {{ form_side|default:"" }} +{% endblock %} - {% block form-side %} - {{ form_side|default:"" }} - {{ publisher.get_request.session.display_message|safe }} - {% endblock %} +{% block body %} {% block form-main %} diff --git a/wcs/templates/wcs/formdata_popup_filling.html b/wcs/templates/wcs/formdata_popup_filling.html index ac4828cb2..aa1ee2a87 100644 --- a/wcs/templates/wcs/formdata_popup_filling.html +++ b/wcs/templates/wcs/formdata_popup_filling.html @@ -6,6 +6,7 @@ {% block sidepage %}{% endblock %} {% block main-content %} +

{{ view.formdef.name }}

{% block form-side %} {{ form_side|default:"" }} {{ publisher.get_request.session.display_message|safe }} @@ -14,4 +15,5 @@ {{ html_form.render|safe }} {% endblock %} +{% block sidebar %}{% endblock %} {% block footer %}{% endblock %} diff --git a/wcs/templates/wcs/formdata_validation.html b/wcs/templates/wcs/formdata_validation.html index 249fca870..2b4a2fe40 100644 --- a/wcs/templates/wcs/formdata_validation.html +++ b/wcs/templates/wcs/formdata_validation.html @@ -1,8 +1,11 @@ {% extends template_base %} +{% block form-side %} + {{ form_side|default:"" }} +{% endblock %} + {% block body %}
- {{ form_side|default:"" }}
{% standard_text "check-before-submit" %}
diff --git a/wcs/views.py b/wcs/views.py index ab295bb47..e75fe08e1 100644 --- a/wcs/views.py +++ b/wcs/views.py @@ -40,6 +40,7 @@ class Backoffice(compat.TemplateWithFallbackView): if isinstance(body, template.QommonTemplateResponse): body.add_media() if body.is_django_native: + self.request.is_django_native = True _request = get_request() self.template_names = body.templates context.update(body.context) -- 2.39.2