Changeset 8166 for main/waeup.kofa/trunk/src
- Timestamp:
- 15 Apr 2012, 17:51:13 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/schema/field.py
r8158 r8166 19 19 """ 20 20 from zope.interface import implements 21 from zope.schema import TextLine, Date , Datetime21 from zope.schema import TextLine, Date 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 , IFormattedDatetime26 from waeup.kofa.schema.interfaces import IFormattedDate 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 these160 attributes in forms, you have to provide widgets that read them161 and use them in their operations, for instance the162 `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 a168 string that can be fed to strftime/strptime functions. By169 default `None`.170 171 `show_time`172 boolean indicating whether also time should be displayed when173 rendering the value of this field. This should usually be174 `True`, so it's also the default.175 """176 implements(IFormattedDatetime)177 date_format = None178 show_time = True179 def __init__(self, date_format=None, show_time=True, *args, **kw):180 self.date_format = date_format181 self.show_time = show_time182 return super(FormattedDatetime, self).__init__(*args, **kw) -
main/waeup.kofa/trunk/src/waeup/kofa/schema/interfaces.py
r8158 r8166 17 17 ## 18 18 from zope import schema 19 from zope.schema.interfaces import IDate , IDatetime19 from zope.schema.interfaces import IDate 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 additional44 attributes. These attributes _can_ be used by widgets to change45 the way of editing or displaying a date.46 47 The waeup.kofa.widgets.datetimewidget.FormattedDatetimeWidget is a48 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
r8158 r8166 3 3 import unittest 4 4 from zope.interface.verify import verifyClass, verifyObject 5 from zope.schema.interfaces import IDate , IDatetime6 from waeup.kofa.schema import FormattedDate , FormattedDatetime7 from waeup.kofa.schema.interfaces import IFormattedDate , IFormattedDatetime5 from zope.schema.interfaces import IDate 6 from waeup.kofa.schema import FormattedDate 7 from waeup.kofa.schema.interfaces import IFormattedDate 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 contracts40 obj = FormattedDatetime()41 verifyClass(IDatetime, FormattedDatetime)42 verifyClass(IFormattedDatetime, FormattedDatetime)43 verifyObject(IDatetime, obj)44 verifyObject(IFormattedDatetime, obj)45 return46 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 return53 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
r8158 r8166 25 25 /> 26 26 27 <adapter28 for="waeup.kofa.schema.interfaces.IFormattedDatetime29 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 <adapter36 for="waeup.kofa.schema.interfaces.IFormattedDatetime37 zope.publisher.interfaces.browser.IBrowserRequest"38 provides="zope.formlib.interfaces.IDisplayWidget"39 factory="waeup.kofa.widgets.datetimewidget.DatetimeLEDisplayWidget"40 permission="zope.Public"41 />42 43 27 </configure>
Note: See TracChangeset for help on using the changeset viewer.