Changeset 8193
- Timestamp:
- 17 Apr 2012, 11:35:01 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py
r8152 r8193 19 19 A datewidget with customizable date format. 20 20 """ 21 import pytz 21 22 from datetime import datetime 23 from zope.component import queryUtility 22 24 from zope.formlib.interfaces import ConversionError, IDisplayWidget 23 25 from zope.formlib.textwidgets import DateWidget, DateDisplayWidget, escape 24 26 from zope.formlib.widget import renderElement, CustomWidgetFactory 25 27 from zope.interface import implements 28 from waeup.kofa.interfaces import IKofaUtils 29 from waeup.kofa.utils.helpers import to_timezone 30 26 31 27 32 #: A dictionary of supported date formats. … … 130 135 131 136 This is a display widget. 137 138 It can also be used for displaying datetimes. If used to display a 139 datetime (not a date), the widget returns local datetime with 140 timezone set according to KofaUtils. 132 141 """ 133 142 date_format = '%Y-%m-%d' … … 152 161 if content == self.context.missing_value: 153 162 return "" 163 if isinstance(content, datetime): 164 # shift value to local timezone 165 tz = pytz.utc 166 utils = queryUtility(IKofaUtils) 167 if utils is not None: 168 tz = utils.tzinfo 169 content = to_timezone(content, tz) 154 170 content = content.strftime(self.date_format) 155 171 return renderElement("span", contents=escape(content),
Note: See TracChangeset for help on using the changeset viewer.