Changeset 6867 for main/waeup.sirp/trunk
- Timestamp:
- 10 Oct 2011, 15:09:28 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/widgets/datewidget.py
r6060 r6867 5 5 ## $Id$ 6 6 ## 7 ## Copyright (C) 2011 Uli Fouquet 7 ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann 8 8 ## This program is free software; you can redistribute it and/or modify 9 9 ## it under the terms of the GNU General Public License as published by … … 26 26 from zope.formlib.i18n import _ 27 27 from zope.formlib.interfaces import ConversionError, IDisplayWidget 28 from zope.formlib.textwidgets import DateWidget, DateDisplayWidget, escape 28 from zope.formlib.textwidgets import ( 29 DateWidget, DateDisplayWidget, escape, DatetimeDisplayWidget) 29 30 from zope.formlib.widget import renderElement, CustomWidgetFactory 30 31 from zope.interface import implements … … 68 69 return "" 69 70 content = content.strftime(self.date_format) 71 return renderElement("span", contents=escape(content), 72 cssClass=self.cssClass) 73 74 class FormattedDatetimeDisplayWidget(DatetimeDisplayWidget): 75 """A datetime widget that supports different (and _explicit_) date formats. 76 77 This is a display widget. 78 """ 79 datetime_format = '%Y-%m-%d %H:%M:%S' 80 implements(IDisplayWidget) 81 82 def __call__(self): 83 if self._renderedValueSet(): 84 content = self._data 85 else: 86 content = self.context.default 87 if content == self.context.missing_value: 88 return "" 89 content = content.strftime(self.datetime_format) 70 90 return renderElement("span", contents=escape(content), 71 91 cssClass=self.cssClass) … … 145 165 FormattedDateDisplayWidget, 146 166 date_format=date_format) 167 168 def FriendlyDatetimeDisplayWidget(format): 169 """Get a friendly datetime display widget for `format`. 170 171 This widget is suitable for display forms. 172 173 Valid `format` values are the keys of :var:`DATE_FORMATS` 174 dict. Default is ``le`` (little endian; DD/MM/YYYY). 175 176 This widget is not rendered with a specialized CSS tag for 177 enabling JavaScript datepickers. `css_class` is ignored which means 178 there is nor difference between e.g. ``le`` and ``le-year``.` 179 """ 180 css_class, date_format = DATE_FORMATS.get(format, DATE_FORMATS['le']) 181 datetime_format = date_format + ' %H:%M:%S' 182 return CustomWidgetFactory( 183 FormattedDatetimeDisplayWidget, 184 datetime_format=datetime_format)
Note: See TracChangeset for help on using the changeset viewer.