Projet

Général

Profil

0001-widgets-allow-manual-fill-in-datetime-widgets-17935.patch

Serghei Mihai (congés, retour 15/05), 24 août 2017 18:49

Télécharger (3,24 ko)

Voir les différences:

Subject: [PATCH] widgets: allow manual fill in datetime widgets (#17935)

 src/authentic2/widgets.py | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
src/authentic2/widgets.py
14 14
from django.forms.widgets import DateTimeInput, DateInput, TimeInput
15 15
from django.utils.formats import get_language
16 16
from django.utils.safestring import mark_safe
17
from django.utils.translation import ugettext_lazy as _
17 18

  
18 19
from gadjo.templatetags.gadjo import xstatic
19 20

  
......
51 52
      %(rendered_widget)s
52 53
      %(clear_button)s
53 54
      <span class="add-on"><i class="icon-th"></i></span>
55
      <span class="helptext">%(format_label)s %(format_text)s</span>
54 56
       <script type="text/javascript">
55 57
           $("#%(id)s").datetimepicker({%(options)s});
56 58
       </script>
......
74 76
    format_name = None
75 77
    glyphicon = None
76 78

  
77
    def __init__(self, attrs=None, options=None, usel10n=None):
79
    def __init__(self, attrs=None, options=None, usel10n=None, format_text=None):
78 80

  
79 81
        if attrs is None:
80
            attrs = {'readonly': ''}
82
            attrs = {}
83

  
84
        if format_text is None:
85
            self.format_text = _('dd/mm/yyyy')
86
        else:
87
            self.format_text = format_text
81 88

  
82 89
        self.options = options
83 90
        self.options['language'] = get_language().split('-')[0]
......
109 116

  
110 117
        # Use provided id or generate hex to avoid collisions in document
111 118
        id = final_attrs.get('id', uuid.uuid4().hex)
112

  
113 119
        return mark_safe(BOOTSTRAP_INPUT_TEMPLATE % dict(
114 120
                    id=id,
115 121
                    rendered_widget=rendered_widget,
116 122
                    clear_button=CLEAR_BTN_TEMPLATE if self.options.get('clearBtn') else '',
117 123
                    glyphicon=self.glyphicon,
118
                    options=js_options
124
                    options=js_options,
125
                    format_label=_('format:'),
126
                    format_text=self.format_text
119 127
                    )
120 128
        )
121 129

  
......
136 144

  
137 145
        # Set the default options to show only the datepicker object
138 146
        options['format'] = options.get('format', 'dd/mm/yyyy hh:ii')
147
        format_text = _('dd/mm/yyyy hh:ii')
139 148

  
140
        super(DateTimeWidget, self).__init__(attrs, options, usel10n)
149
        super(DateTimeWidget, self).__init__(attrs, options, usel10n, format_text)
141 150

  
142 151

  
143 152
class DateWidget(PickerWidgetMixin, DateInput):
......
181 190
        options['minView'] = options.get('minView', 0)
182 191
        options['maxView'] = options.get('maxView', 1)
183 192
        options['format'] = options.get('format', 'hh:ii')
193
        format_text = _('hh:ii')
184 194

  
185
        super(TimeWidget, self).__init__(attrs, options, usel10n)
195
        super(TimeWidget, self).__init__(attrs, options, usel10n, format_text)
186
-