Projet

Général

Profil

0001-general-pass-quixote-form-as-html_form-to-templates-.patch

Frédéric Péters, 18 décembre 2021 17:36

Télécharger (6,31 ko)

Voir les différences:

Subject: [PATCH] general: pass quixote form as "html_form" to templates
 (#59882)

"form" is kept for legacy external templates (in publik-base-theme), to
be removed once those templates are updated to use html_form.
 wcs/backoffice/data_management.py                       | 2 +-
 wcs/forms/actions.py                                    | 2 +-
 wcs/forms/root.py                                       | 6 ++++--
 wcs/qommon/template.py                                  | 7 ++++---
 wcs/templates/wcs/action.html                           | 2 +-
 wcs/templates/wcs/backoffice/card-data-import-form.html | 2 +-
 wcs/templates/wcs/formdata_filling.html                 | 2 +-
 wcs/templates/wcs/formdata_popup_filling.html           | 2 +-
 wcs/templates/wcs/formdata_validation.html              | 2 +-
 9 files changed, 15 insertions(+), 12 deletions(-)
wcs/backoffice/data_management.py
207 207

  
208 208
        get_response().breadcrumb.append(('import_csv', _('Import CSV')))
209 209
        html_top('data_management', _('Import CSV'))
210
        context['form'] = form
210
        context['html_form'] = form
211 211

  
212 212
        for field in self.get_import_csv_fields():
213 213
            if not hasattr(field, 'required'):
wcs/forms/actions.py
68 68
            return self.submit()
69 69
        context = {
70 70
            'view': self,
71
            'form': form,
71
            'html_form': form,
72 72
        }
73 73
        return template.QommonTemplateResponse(
74 74
            templates=list(self.get_formdef_template_variants(self.templates)), context=context
wcs/forms/root.py
621 621
            context['tracking_code_box'] = lambda: self.tracking_code_box(data, magictoken)
622 622
        self.modify_filling_context(context, page, data)
623 623

  
624
        context['html_form'] = form
624 625
        if self.is_popup:
625
            context['form_obj'] = form
626 626
            return template.QommonTemplateResponse(
627 627
                templates=list(self.get_formdef_template_variants(self.popup_filling_templates)),
628 628
                context=context,
629 629
                is_django_native=True,
630 630
            )
631 631
        else:
632
            # legacy
632 633
            context['form'] = form
633 634

  
634 635
        return template.QommonTemplateResponse(
......
1649 1650

  
1650 1651
        context = {
1651 1652
            'view': self,
1652
            'form': form,
1653
            'html_form': form,
1653 1654
            'form_side': lambda: self.form_side(step_no=1, page=None, data=data, magictoken=magictoken),
1654 1655
            'steps': lambda: self.step(1, None),
1655 1656
        }
1657
        context['form'] = form  # legacy
1656 1658
        if self.has_draft_support() and data:
1657 1659
            context['tracking_code_box'] = lambda: self.tracking_code_box(data, magictoken)
1658 1660
        return template.QommonTemplateResponse(
wcs/qommon/template.py
422 422

  
423 423
    def add_media(self):
424 424
        # run add_media so we get them in the page <head>
425
        if 'form' in self.context:
425
        if 'html_form' in self.context:
426
            self.context['html_form'].add_media()
427
        if 'form' in self.context and hasattr(self.context['form'], 'add_media'):
428
            # legacy name, conflicting with formdata "form*" variables
426 429
            self.context['form'].add_media()
427
        if 'form_obj' in self.context:  # "add card" popup case
428
            self.context['form_obj'].add_media()
429 430

  
430 431

  
431 432
class TemplateError(Exception):
wcs/templates/wcs/action.html
10 10
<p>
11 11
{% trans "Please confirm action." %}
12 12
</p>
13
{{ form.render|safe }}
13
{{ html_form.render|safe }}
14 14
{% endif %}
15 15
{% endblock %}
wcs/templates/wcs/backoffice/card-data-import-form.html
22 22
{% else %}
23 23
<p>{% trans "You can add data to this card by uploading a file." %}</p>
24 24
<p><a href="data-sample-csv">{% trans "Download sample file for this card" %}</a></p>
25
{{ form.render|safe }}
25
{{ html_form.render|safe }}
26 26
{% endif %}
27 27
{% endblock %}
wcs/templates/wcs/formdata_filling.html
44 44
{% endif %}
45 45
{% endblock %}
46 46

  
47
{{ form.render|safe }}
47
{{ html_form.render|safe }}
48 48
{% endblock %}
49 49

  
50 50
{% endblock %}
wcs/templates/wcs/formdata_popup_filling.html
11 11
{{ publisher.get_request.session.display_message|safe }}
12 12
{% endblock %}
13 13

  
14
{{ form_obj.render|safe }}
14
{{ html_form.render|safe }}
15 15
{% endblock %}
16 16

  
17 17
{% block footer %}{% endblock %}
wcs/templates/wcs/formdata_validation.html
6 6
 <div class="infonotice">
7 7
 {% standard_text "check-before-submit" %}
8 8
 </div>
9
 {{ form.render|safe }}
9
 {{ html_form.render|safe }}
10 10
</div>
11 11
{% endblock %}
12
-