Projet

Général

Profil

0001-forms-move-fargo-markup-out-of-hint-into-widget-cont.patch

Frédéric Péters, 17 décembre 2018 09:53

Télécharger (3,5 ko)

Voir les différences:

Subject: [PATCH 1/3] forms: move fargo markup out of hint, into widget control
 proper (#28034)

 wcs/qommon/form.py                            | 20 +------------------
 .../templates/qommon/forms/widgets/file.html  | 10 ++++++++++
 2 files changed, 11 insertions(+), 19 deletions(-)
wcs/qommon/form.py
634 634
            self.max_file_size_bytes = FileSizeWidget.parse_file_size(self.max_file_size)
635 635
        self.add(HiddenWidget, 'token')
636 636
        if not self.readonly:
637
            hint = ''
638
            if self.allow_portfolio_picking:
639
                root_url = get_publisher().get_root_url()
640
                if get_request().user:
641
                    params = (root_url,
642
                              _('Pick a file from the portfolio'),
643
                              _('Use file from the portfolio'))
644
                    hint += htmltext('<p class="use-file-from-fargo"><span '
645
                                     'data-src="%sfargo/pick" '
646
                                     'data-width="500" '
647
                                     'data-height="400" '
648
                                     'data-title="%s" '
649
                                     'rel="popup">%s</span></p>' % params)
650
                    # relative fargo.js is added later in self.render_content()
651
            hint += self.hint or ''
652 637
            attrs = {'data-url': get_publisher().get_root_url() + 'tmp-upload'}
653 638
            self.file_type = kwargs.pop('file_type', None)
654 639
            if self.file_type:
......
656 641
            if self.max_file_size_bytes:
657 642
                # this could be used for client size validation of file size
658 643
                attrs['data-max-file-size'] = str(self.max_file_size_bytes)
659
            self.add(FileWidget, 'file', hint=hint, render_br=False, attrs=attrs)
644
            self.add(FileWidget, 'file', render_br=False, attrs=attrs)
660 645
        if value:
661 646
            self.set_value(value)
662 647

  
......
769 754
            if not valid_file_type:
770 755
                self.error = _('invalid file type')
771 756

  
772
    def render_hint(self, hint):
773
        return ''
774

  
775 757

  
776 758
class PicklableUpload(Upload):
777 759
    def __getstate__(self):
wcs/qommon/templates/qommon/forms/widgets/file.html
2 2
{% load i18n %}
3 3

  
4 4
{% block widget-control %}
5
<div class="file-button">
5 6
{% for w in widget.get_widgets %}
6 7
  {{ w.render|safe }}
7 8
{% endfor %}
......
16 17
  <img alt="" src="tempfile?t={{ widget.tempfile.token }}&thumbnail=1"/>
17 18
{% endif %}
18 19
</div>
20
</div>
21
{% block portfolio-picker %}
22
{% if not widget.readonly and widget.allow_portfolio_picking and session_user %}
23
  <p class="use-file-from-fargo"><span
24
     data-src="{{site_url}}/fargo/pick" data-width="500" data-height="400"
25
     data-title="{% trans "Pick a file from the portfolio" %}"
26
     rel="popup">{% trans "Use file from the portfolio" %}</span></p>
27
{% endif %}
28
{% endblock %}
19 29
{% endblock %}
20
-