Changeset 8158 for main/waeup.kofa/trunk
- Timestamp:
- 15 Apr 2012, 00:30:20 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/schema/field.py
r8151 r8158 19 19 """ 20 20 from zope.interface import implements 21 from zope.schema import TextLine, Date 21 from zope.schema import TextLine, Date, Datetime 22 22 from zope.schema.interfaces import ( 23 23 ITextLine, IBaseVocabulary, ISource, IContextSourceBinder, InvalidValue,) 24 24 from zope.schema.vocabulary import ( 25 25 SimpleVocabulary, getVocabularyRegistry, VocabularyRegistryError) 26 from waeup.kofa.schema.interfaces import IFormattedDate 26 from waeup.kofa.schema.interfaces import IFormattedDate, IFormattedDatetime 27 27 28 28 class CustomizableErrorMsg(object): … … 153 153 self.show_year = show_year 154 154 return super(FormattedDate, self).__init__(*args, **kw) 155 156 class FormattedDatetime(Datetime): 157 """A datetime field that supports additional formatting attributes. 158 159 Stores extra attributes (see below). To make use of these 160 attributes in forms, you have to provide widgets that read them 161 and use them in their operations, for instance the 162 `waeup.kofa.widgets.datewidget.FormattedDatetimeWidget`. 163 164 Extra attributes are as follows: 165 166 `date_format` 167 additional attribute to describe desired date format. Must be a 168 string that can be fed to strftime/strptime functions. By 169 default `None`. 170 171 `show_time` 172 boolean indicating whether also time should be displayed when 173 rendering the value of this field. This should usually be 174 `True`, so it's also the default. 175 """ 176 implements(IFormattedDatetime) 177 date_format = None 178 show_time = True 179 def __init__(self, date_format=None, show_time=True, *args, **kw): 180 self.date_format = date_format 181 self.show_time = show_time 182 return super(FormattedDatetime, self).__init__(*args, **kw) -
main/waeup.kofa/trunk/src/waeup/kofa/schema/interfaces.py
r8146 r8158 17 17 ## 18 18 from zope import schema 19 from zope.schema.interfaces import IDate 19 from zope.schema.interfaces import IDate, IDatetime 20 20 21 21 class IFormattedDate(IDate): … … 37 37 default = '%Y-%m-%d', 38 38 ) 39 40 class IFormattedDatetime(IDatetime): 41 """A formatted datetime. 42 43 Basically a zope.schema.IDatetime, but with optional additional 44 attributes. These attributes _can_ be used by widgets to change 45 the way of editing or displaying a date. 46 47 The waeup.kofa.widgets.datetimewidget.FormattedDatetimeWidget is a 48 widget that supports these additional attributes. 49 """ 50 show_time = schema.Bool( 51 title = u'Show time when displaying this date?', 52 default = True, 53 ) 54 date_format = schema.ASCII( 55 title = u'A date format string suitable for use with strftime.', 56 default = '%Y-%m-%d %H:%M:%S', 57 ) -
main/waeup.kofa/trunk/src/waeup/kofa/schema/tests/test_fields.py
r8151 r8158 3 3 import unittest 4 4 from zope.interface.verify import verifyClass, verifyObject 5 from zope.schema.interfaces import IDate 6 from waeup.kofa.schema import FormattedDate 7 from waeup.kofa.schema.interfaces import IFormattedDate 5 from zope.schema.interfaces import IDate, IDatetime 6 from waeup.kofa.schema import FormattedDate, FormattedDatetime 7 from waeup.kofa.schema.interfaces import IFormattedDate, IFormattedDatetime 8 8 9 9 class FormattedDateTests(unittest.TestCase): … … 32 32 self.assertEqual(obj.date_format, '%d.%m.%Y') 33 33 return 34 35 class FormattedDatetimeTests(unittest.TestCase): 36 # Tests for FormattedDatetime field. 37 38 def test_iface(self): 39 # make sure we fullfill interface contracts 40 obj = FormattedDatetime() 41 verifyClass(IDatetime, FormattedDatetime) 42 verifyClass(IFormattedDatetime, FormattedDatetime) 43 verifyObject(IDatetime, obj) 44 verifyObject(IFormattedDatetime, obj) 45 return 46 47 def test_defaults(self): 48 # we get expected default values for datetimes. 49 obj = FormattedDatetime() 50 self.assertEqual(obj.show_time, True) 51 self.assertEqual(obj.date_format, None) 52 return 53 54 def test_attribs(self): 55 # we can set the promised attributes. 56 obj = FormattedDatetime(show_time=False, 57 date_format='%d.%m.%Y %H:%M:%S Uhr') 58 self.assertEqual(obj.show_time, False) 59 self.assertEqual(obj.date_format, '%d.%m.%Y %H:%M:%S Uhr') 60 return -
main/waeup.kofa/trunk/src/waeup/kofa/widgets/overrides.zcml
r8157 r8158 25 25 /> 26 26 27 <adapter 28 for="waeup.kofa.schema.interfaces.IFormattedDatetime 29 zope.publisher.interfaces.browser.IBrowserRequest" 30 provides="zope.formlib.interfaces.ISimpleInputWidget" 31 factory="waeup.kofa.widgets.datetimewidget.DatetimeLEWidget" 32 permission="zope.Public" 33 /> 34 35 <adapter 36 for="waeup.kofa.schema.interfaces.IFormattedDatetime 37 zope.publisher.interfaces.browser.IBrowserRequest" 38 provides="zope.formlib.interfaces.IDisplayWidget" 39 factory="waeup.kofa.widgets.datetimewidget.DatetimeLEDisplayWidget" 40 permission="zope.Public" 41 /> 42 27 43 </configure>
Note: See TracChangeset for help on using the changeset viewer.