- Timestamp:
- 12 May 2011, 01:24:03 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/widgets/datewidget.py
r6052 r6056 25 25 from datetime import datetime 26 26 from zope.formlib.i18n import _ 27 from zope.formlib.interfaces import ConversionError 27 from zope.formlib.interfaces import ConversionError, IDisplayWidget 28 28 from zope.formlib.textwidgets import DateWidget, DateDisplayWidget, escape 29 from zope.formlib.widget import renderElement 29 from zope.formlib.widget import renderElement, CustomWidgetFactory 30 from zope.interface import implements 30 31 31 32 class FormattedDateWidget(DateWidget): … … 57 58 """ 58 59 date_format = '%Y-%m-%d' 59 60 implements(IDisplayWidget) 61 60 62 def __call__(self): 61 63 if self._renderedValueSet(): … … 68 70 return renderElement("span", contents=escape(content), 69 71 cssClass=self.cssClass) 72 73 #: A dictionary of supported date formats. 74 DATE_FORMATS = { 75 'iso': ('datepicker', '%Y-%m-%d'), 76 'le': ('datepicker-le', '%d/%m/%Y'), 77 'de': ('datepicker-de', '%d.%m.%Y'), 78 'us': ('datepicker-us', '%m/%d/%Y'), 79 'iso-year': ('datepicker-year', '%Y-%m-%d'), 80 'le-year': ('datepicker-le-year', '%d/%m/%Y'), 81 'de-year': ('datepicker-de-year', '%d.%m.%Y'), 82 'us-year': ('datepicker-us-year', '%m/%d/%Y'), 83 } 84 def FriendlyDateWidget(format): 85 """Get a friendly date input widget for `format`. 86 """ 87 css_class, date_format = DATE_FORMATS.get(format, DATE_FORMATS['le']) 88 return CustomWidgetFactory( 89 FormattedDateWidget, 90 cssClass=css_class, 91 date_format=date_format) 92 93 def FriendlyDateDisplayWidget(format): 94 """Get a friendly date display widget for `format`. 95 """ 96 css_class, date_format = DATE_FORMATS.get(format, DATE_FORMATS['le']) 97 return CustomWidgetFactory( 98 FormattedDateDisplayWidget, 99 date_format=date_format)
Note: See TracChangeset for help on using the changeset viewer.