From cddc7e4f8c4d8c689fc9b2d375b1072cfdd98a3a Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Thu, 24 Aug 2017 18:12:46 +0200 Subject: [PATCH] widgets: allow manual fill in datetime widgets (#17935) --- src/authentic2/widgets.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/authentic2/widgets.py b/src/authentic2/widgets.py index 7c643cf3..fc34b70f 100644 --- a/src/authentic2/widgets.py +++ b/src/authentic2/widgets.py @@ -14,6 +14,7 @@ import uuid from django.forms.widgets import DateTimeInput, DateInput, TimeInput from django.utils.formats import get_language from django.utils.safestring import mark_safe +from django.utils.translation import ugettext_lazy as _ from gadjo.templatetags.gadjo import xstatic @@ -51,6 +52,7 @@ BOOTSTRAP_INPUT_TEMPLATE = """ %(rendered_widget)s %(clear_button)s + %(format_label)s %(format_text)s @@ -74,10 +76,15 @@ class PickerWidgetMixin(object): format_name = None glyphicon = None - def __init__(self, attrs=None, options=None, usel10n=None): + def __init__(self, attrs=None, options=None, usel10n=None, format_text=None): if attrs is None: - attrs = {'readonly': ''} + attrs = {} + + if format_text is None: + self.format_text = _('dd/mm/yyyy') + else: + self.format_text = format_text self.options = options self.options['language'] = get_language().split('-')[0] @@ -109,13 +116,14 @@ class PickerWidgetMixin(object): # Use provided id or generate hex to avoid collisions in document id = final_attrs.get('id', uuid.uuid4().hex) - return mark_safe(BOOTSTRAP_INPUT_TEMPLATE % dict( id=id, rendered_widget=rendered_widget, clear_button=CLEAR_BTN_TEMPLATE if self.options.get('clearBtn') else '', glyphicon=self.glyphicon, - options=js_options + options=js_options, + format_label=_('format:'), + format_text=self.format_text ) ) @@ -136,8 +144,9 @@ class DateTimeWidget(PickerWidgetMixin, DateTimeInput): # Set the default options to show only the datepicker object options['format'] = options.get('format', 'dd/mm/yyyy hh:ii') + format_text = _('dd/mm/yyyy hh:ii') - super(DateTimeWidget, self).__init__(attrs, options, usel10n) + super(DateTimeWidget, self).__init__(attrs, options, usel10n, format_text) class DateWidget(PickerWidgetMixin, DateInput): @@ -181,5 +190,6 @@ class TimeWidget(PickerWidgetMixin, TimeInput): options['minView'] = options.get('minView', 0) options['maxView'] = options.get('maxView', 1) options['format'] = options.get('format', 'hh:ii') + format_text = _('hh:ii') - super(TimeWidget, self).__init__(attrs, options, usel10n) + super(TimeWidget, self).__init__(attrs, options, usel10n, format_text) -- 2.14.1