[Checkins] SVN: zc.datetimewidget/trunk/src/zc/datetimewidget/ fixed tofieldvalue of datewidget, which returned a datetime object; added tests for this

Bernd Dorn bernd.dorn at fhv.at
Tue Nov 14 16:45:15 EST 2006


Log message for revision 71123:
  fixed tofieldvalue of datewidget, which returned a datetime object; added tests for this

Changed:
  U   zc.datetimewidget/trunk/src/zc/datetimewidget/datetimewidget.py
  U   zc.datetimewidget/trunk/src/zc/datetimewidget/tests.py
  D   zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt
  A   zc.datetimewidget/trunk/src/zc/datetimewidget/widgets.txt

-=-
Modified: zc.datetimewidget/trunk/src/zc/datetimewidget/datetimewidget.py
===================================================================
--- zc.datetimewidget/trunk/src/zc/datetimewidget/datetimewidget.py	2006-11-14 15:49:11 UTC (rev 71122)
+++ zc.datetimewidget/trunk/src/zc/datetimewidget/datetimewidget.py	2006-11-14 21:45:14 UTC (rev 71123)
@@ -117,7 +117,7 @@
     _format = '%Y-%m-%d %H:%M:%S'
     _showsTime = "true"
 
-    def _toFieldValue(self, input):
+    def _toFieldValue(self, input):        
         res = super(DatetimeWidget, self)._toFieldValue(input)
         if res is not self.context.missing_value:
             res = normalizeDateTime(res, self.request)
@@ -130,6 +130,7 @@
 
     _format = '%Y-%m-%d'
     _showsTime = "false"
+    _toFieldValue = textwidgets.DateWidget._toFieldValue
 
 
 class DatetimeDisplayBase(object):

Modified: zc.datetimewidget/trunk/src/zc/datetimewidget/tests.py
===================================================================
--- zc.datetimewidget/trunk/src/zc/datetimewidget/tests.py	2006-11-14 15:49:11 UTC (rev 71122)
+++ zc.datetimewidget/trunk/src/zc/datetimewidget/tests.py	2006-11-14 21:45:14 UTC (rev 71123)
@@ -13,7 +13,7 @@
 ##############################################################################
 """Datetime Widget unittests
 
-$Id:$
+$Id$
 """
 __docformat__ = "reStructuredText"
 
@@ -34,7 +34,7 @@
 def test_suite():
     return unittest.TestSuite(
         (
-        DocFileSuite('timezones.txt',
+        DocFileSuite('widgets.txt',
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
                      ),
         ))

Deleted: zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt
===================================================================
--- zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt	2006-11-14 15:49:11 UTC (rev 71122)
+++ zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt	2006-11-14 21:45:14 UTC (rev 71123)
@@ -1,50 +0,0 @@
-==================
-Handling Timezones
-==================
-
-Datetimes are always stored timezone aware, and by default the utc
-timezone is used. We use the demo package here to have a content class
-and interface.
-
-In order to handle timezones correctly the zope instance has to
-provide an adapter from IBrowserRequest to ITZInfo. It is up to the
-instance what kind of implementation it uses. For this test, we just
-use the implementation of the demo.timezone module which always
-returns Europe/Vienna as timezone.
-
-    >>> from zope import component
-    >>> from datetime import datetime
-    >>> import pytz
-    >>> from zc.datetimewidget import datetimewidget
-    >>> from zc.datetimewidget.demo import timezone
-    >>> from zc.datetimewidget.demo.content import DemoContent
-    >>> from zc.datetimewidget.demo.interfaces import IDemoContent
-    >>> from zope.publisher.browser import TestRequest, BrowserLanguages
-    >>> component.provideAdapter(BrowserLanguages)
-    >>> request = TestRequest(HTTP_ACCEPT_LANGUAGE='en-US')
-    >>> component.provideAdapter(timezone.tzinfo)
-    >>> tz = pytz.timezone('Europe/Vienna')
-    >>> field = IDemoContent['startDatetime']
-    >>> widget = datetimewidget.DatetimeWidget(field,request)
-    >>> dt = datetime(2006,5,1,12,tzinfo=pytz.utc)
-
-The field's missing value results in an empty string.
-
-    >>> widget._toFormValue(None)
-    u''
-
-Now let us convert a real datetime.
-
-    >>> formValue = widget._toFormValue(dt)
-    >>> formValue
-    '2006-05-01 14:00:00'
-    >>> parsedValue = widget._toFieldValue(formValue)
-    >>> parsedValue
-    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)
-
-While the widget tries to parse dates in the form '%Y-%m-%d %H:%M:%S'
-first, it will fall through to the locale-specific parsing of the core
-datetimewidget.
-
-    >>> widget._toFieldValue('May 1, 2006 2:00:00 PM')
-    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)

Copied: zc.datetimewidget/trunk/src/zc/datetimewidget/widgets.txt (from rev 71122, zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt)
===================================================================
--- zc.datetimewidget/trunk/src/zc/datetimewidget/timezones.txt	2006-11-14 15:49:11 UTC (rev 71122)
+++ zc.datetimewidget/trunk/src/zc/datetimewidget/widgets.txt	2006-11-14 21:45:14 UTC (rev 71123)
@@ -0,0 +1,83 @@
+=========================
+Datetime and Date Widgets
+=========================
+
+There are two types of widgets provided by this package, a date widget
+and a datetime widget.
+
+Date Widget
+===========
+
+The date widget only handles datetime.date objects, which are not
+timezone aware. We use the demo package here to have a content class.
+
+    >>> from zope import component
+    >>> from datetime import datetime, date
+    >>> from zc.datetimewidget import datetimewidget
+    >>> from zc.datetimewidget.demo.content import DemoContent
+    >>> from zc.datetimewidget.demo.interfaces import IDemoContent
+    >>> from zope.publisher.browser import TestRequest, BrowserLanguages
+    >>> component.provideAdapter(BrowserLanguages)
+    >>> request = TestRequest(HTTP_ACCEPT_LANGUAGE='en-US')
+    >>> field = IDemoContent['startDate']
+    >>> widget = datetimewidget.DateWidget(field,request)
+    >>> widget._toFormValue(None)
+    u''
+
+Now let us convert a real date.
+
+    >>> d = date(2006,5,1)
+    >>> formValue = widget._toFormValue(d)
+    >>> formValue
+    '2006-05-01'
+
+    >>> parsedValue = widget._toFieldValue(formValue)
+    >>> parsedValue
+    datetime.date(2006, 5, 1)
+
+The widget handles the same date notations as zope's default datewidget.
+
+    >>> widget._toFieldValue('2006/12/31')
+    datetime.date(2006, 12, 31)
+
+Datetime Widget
+===============
+
+Datetimes are always stored timezone aware, and by default the utc
+timezone is used.
+
+In order to handle timezones correctly the zope instance has to
+provide an adapter from IBrowserRequest to ITZInfo. It is up to the
+instance what kind of implementation it uses. For this test, we just
+use the implementation of the demo.timezone module which always
+returns Europe/Vienna as timezone.
+
+The field's missing value results in an empty string.
+
+    >>> import pytz
+    >>> from zc.datetimewidget.demo import timezone
+    >>> component.provideAdapter(timezone.tzinfo)
+    >>> tz = pytz.timezone('Europe/Vienna')
+    >>> request = TestRequest(HTTP_ACCEPT_LANGUAGE='en-US')
+    >>> field = IDemoContent['startDatetime']
+    >>> widget = datetimewidget.DatetimeWidget(field,request)
+    >>> dt = datetime(2006,5,1,12,tzinfo=pytz.utc)
+
+    >>> widget._toFormValue(None)
+    u''
+
+Now let us convert a real datetime.
+
+    >>> formValue = widget._toFormValue(dt)
+    >>> formValue
+    '2006-05-01 14:00:00'
+    >>> parsedValue = widget._toFieldValue(formValue)
+    >>> parsedValue
+    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)
+
+While the widget tries to parse dates in the form '%Y-%m-%d %H:%M:%S'
+first, it will fall through to the locale-specific parsing of the core
+datetimewidget.
+
+    >>> widget._toFieldValue('May 1, 2006 2:00:00 PM')
+    datetime.datetime(2006, 5, 1, 12, 0, tzinfo=<UTC>)



More information about the Checkins mailing list