[Testbot] Plone 5.0 - Python 2.7 - Build # 2299 - Regression! - 1 failure(s)

jenkins at plone.org jenkins at plone.org
Thu Apr 17 13:35:35 UTC 2014


-------------------------------------------------------------------------------
Plone 5.0 - Python 2.7 - Build # 2299 - Failure!
-------------------------------------------------------------------------------

http://jenkins.plone.org/job/plone-5.0-python-2.7/2299/


-------------------------------------------------------------------------------
CHANGES
-------------------------------------------------------------------------------

Repository: plone.app.widgets
Branch: refs/heads/master
Date: 2014-04-16T01:37:42+02:00
Author: Johannes Raggam (thet) <raggam-nl at adm.at>
Commit: https://github.com/plone/plone.app.widgets/commit/99578e174d9ae83ffb38b09d95ef8f9018d78a83

Add default_timezone widget attribute to DatetimeWidget. If used and set to a valid Olson DB/pytz timezone identifier or to an callback returning such, the datetime object returned by the widget will be localized to that timezone. This changes the timezone related behavior from version 1.4.0.

Files changed:
M CHANGES.rst
M plone/app/widgets/dx.py
M plone/app/widgets/tests/test_dx.py

diff --git a/CHANGES.rst b/CHANGES.rst
index c76592c..5f1c1d0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,12 @@ Changelog
 1.6.0 (unreleased)
 ------------------
 
+- Add default_timezone widget attribute to DatetimeWidget. If used and set to a
+  valid Olson DB/pytz timezone identifier or to an callback returning such, the
+  datetime object returned by the widget will be localized to that timezone.
+  This changes the timezone related behavior from version 1.4.0.
+  [thet]
+
 - fix related items widget using getSource when it should use getVocabulary
   [davisagli]
 
diff --git a/plone/app/widgets/dx.py b/plone/app/widgets/dx.py
index c9d66cc..3ee5a67 100644
--- a/plone/app/widgets/dx.py
+++ b/plone/app/widgets/dx.py
@@ -2,6 +2,7 @@
 
 from AccessControl import getSecurityManager
 from Products.CMFCore.utils import getToolByName
+from Products.CMFPlone.utils import safe_callable
 from datetime import date
 from datetime import datetime
 
@@ -195,27 +196,15 @@ def toFieldValue(self, value):
         else:
             value += ['00', '00']
 
-        # Eventually set timezone
-        old_val = getattr(self.widget.context, self.field.getName(), None)
-        if getattr(old_val, 'tzinfo', False):
-            # Only set when field was previously set and only if it's value
-            # is a timezone aware datetime object.
-            # effective date for example is timezone naive, at the moment.
-            #
-            # We only ask, if there is a timezone information at all but try to
-            # use the 'timezone' attribute on the widget's context, since it
-            # represents the timezone, the event and it's form input are
-            # related to.
-            timezone = getattr(self.widget.context, 'timezone', None)
-            if timezone:
-                # plone.app.event stores it's timezone on the context.
-                timezone = pytz.timezone(timezone)
-            else:
-                # This better should use the tzinfo object from old_val. But we
-                # have to find, how to correctly localize the value with it.
-                timezone = pytz.utc
-            return timezone.localize(datetime(*map(int, value)))
-        return datetime(*map(int, value))
+        # TODO: respect the selected zone from the widget and just fall back
+        # to default_zone
+        default_zone = self.widget.default_timezone
+        zone = default_zone() if safe_callable(default_zone) else default_zone
+        ret = datetime(*map(int, value))
+        if zone:
+            tzinfo = pytz.timezone(zone)
+            ret = tzinfo.localize(ret)
+        return ret
 
 
 class SelectWidgetConverterBase(object):
@@ -511,7 +500,13 @@ def render(self):
 
 
 class DatetimeWidget(DateWidget, HTMLInputWidget):
-    """Datetime widget for z3c.form."""
+    """Datetime widget for z3c.form.
+
+    :param default_timezone: A Olson DB/pytz timezone identifier or a callback
+                             returning such an identifier.
+    :type default_timezone: String or callback
+
+    """
 
     _converter = DatetimeWidgetConverter
     _formater = 'dateTime'
@@ -520,6 +515,8 @@ class DatetimeWidget(DateWidget, HTMLInputWidget):
 
     pattern_options = DateWidget.pattern_options.copy()
 
+    default_timezone = None
+
     def _base_args(self):
         """Method which will calculate _base class arguments.
 
diff --git a/plone/app/widgets/tests/test_dx.py b/plone/app/widgets/tests/test_dx.py
index 9bfb630..7d5241f 100644
--- a/plone/app/widgets/tests/test_dx.py
+++ b/plone/app/widgets/tests/test_dx.py
@@ -1,5 +1,4 @@
 # -*- coding: utf-8 -*-
-
 from datetime import date
 from datetime import datetime
 from mock import Mock
@@ -36,6 +35,7 @@
 
 import mock
 import json
+import pytz
 
 try:
     import unittest2 as unittest
@@ -271,56 +271,71 @@ def test_data_converter(self):
             '21-10-30 15:40',
         )
 
-    def test_data_converter_timezone(self):
+    def test_data_converter__no_timezone(self):
+        """When no timezone is set, don't apply one.
+        """
         from plone.app.widgets.dx import DatetimeWidgetConverter
         context = Mock()
 
-        # Test for previously set datetime, without tzinfo and no timezone on
-        # context.
-        # Should not apply a timezone to the field value.
         dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
         self.widget.context = context
+        self.widget.default_timezone = None
+
         converter = DatetimeWidgetConverter(self.field, self.widget)
         self.assertEqual(
             converter.toFieldValue('2013-11-13 10:20'),
             datetime(2013, 11, 13, 10, 20),
         )
 
-        # Test for previously set datetime, with tzinfo but no timezone on
-        # context.
-        # Should apply UTZ zone to field value, to be able to be compared with
-        # the timezone aware datetime from the context.
-        import pytz
-        nl = pytz.timezone('Europe/Amsterdam')
-        dt = nl.localize(datetime(2013, 11, 13, 10, 20))
+        # cleanup
+        self.widget.context = None
+        self.widget.default_timezone = None
+
+    def test_data_converter__timezone_id(self):
+        """When a (pytz) timezone id is set, use that.
+        """
+        from plone.app.widgets.dx import DatetimeWidgetConverter
+        context = Mock()
+
+        dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
-        context.timezone = None
         self.widget.context = context
+        self.widget.default_timezone = 'Europe/Vienna'
+        tz = pytz.timezone('Europe/Vienna')
+
         converter = DatetimeWidgetConverter(self.field, self.widget)
         self.assertEqual(
             converter.toFieldValue('2013-11-13 10:20'),
-            pytz.utc.localize(datetime(2013, 11, 13, 10, 20)),
+            tz.localize(datetime(2013, 11, 13, 10, 20)),
         )
 
-        # Test for previously set datetime, with tzinfo and timezone one
-        # context.
-        # Should apply the zone based on "timezone" value to field value, to be
-        # able to be CORRECTLY compared with the timezone aware datetime from
-        # the context.
-        nl = pytz.timezone('Europe/Amsterdam')
-        dt = nl.localize(datetime(2013, 11, 13, 10, 20))
+        # cleanup
+        self.widget.context = None
+        self.widget.default_timezone = None
+
+    def test_data_converter__timezone_callback(self):
+        """When a timezone callback is set, returning a (pytz) timezone id,
+        use that.
+        """
+        from plone.app.widgets.dx import DatetimeWidgetConverter
+        context = Mock()
+
+        dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
-        context.timezone = "Europe/Amsterdam"
         self.widget.context = context
+        self.widget.default_timezone = lambda: 'Europe/Vienna'
+        tz = pytz.timezone('Europe/Vienna')
+
         converter = DatetimeWidgetConverter(self.field, self.widget)
         self.assertEqual(
             converter.toFieldValue('2013-11-13 10:20'),
-            nl.localize(datetime(2013, 11, 13, 10, 20)),
+            tz.localize(datetime(2013, 11, 13, 10, 20)),
         )
 
         # cleanup
         self.widget.context = None
+        self.widget.default_timezone = None
 
     def test_fieldwidget(self):
         from plone.app.widgets.dx import DatetimeWidget


Repository: plone.app.widgets
Branch: refs/heads/master
Date: 2014-04-16T01:37:42+02:00
Author: Johannes Raggam (thet) <raggam-nl at adm.at>
Commit: https://github.com/plone/plone.app.widgets/commit/9ba43086788efa75ae85fab47ed03affefb234c7

that was first started at Arnhemsprint 2013, so...

Files changed:
M plone/app/widgets/tests/test_dx.py

diff --git a/plone/app/widgets/tests/test_dx.py b/plone/app/widgets/tests/test_dx.py
index 7d5241f..1a4ead1 100644
--- a/plone/app/widgets/tests/test_dx.py
+++ b/plone/app/widgets/tests/test_dx.py
@@ -301,8 +301,8 @@ def test_data_converter__timezone_id(self):
         dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
         self.widget.context = context
-        self.widget.default_timezone = 'Europe/Vienna'
-        tz = pytz.timezone('Europe/Vienna')
+        self.widget.default_timezone = 'Europe/Amsterdam'
+        tz = pytz.timezone('Europe/Amsterdam')
 
         converter = DatetimeWidgetConverter(self.field, self.widget)
         self.assertEqual(
@@ -324,8 +324,8 @@ def test_data_converter__timezone_callback(self):
         dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
         self.widget.context = context
-        self.widget.default_timezone = lambda: 'Europe/Vienna'
-        tz = pytz.timezone('Europe/Vienna')
+        self.widget.default_timezone = lambda: 'Europe/Amsterdam'
+        tz = pytz.timezone('Europe/Amsterdam')
 
         converter = DatetimeWidgetConverter(self.field, self.widget)
         self.assertEqual(


Repository: plone.app.widgets
Branch: refs/heads/master
Date: 2014-04-16T01:37:42+02:00
Author: Johannes Raggam (thet) <raggam-nl at adm.at>
Commit: https://github.com/plone/plone.app.widgets/commit/d9d8cf37729fdf394fa0a138c323d9f5278408c1

pass widgets context to default_timezone

Files changed:
M plone/app/widgets/dx.py

diff --git a/plone/app/widgets/dx.py b/plone/app/widgets/dx.py
index 3ee5a67..bddd717 100644
--- a/plone/app/widgets/dx.py
+++ b/plone/app/widgets/dx.py
@@ -199,7 +199,8 @@ def toFieldValue(self, value):
         # TODO: respect the selected zone from the widget and just fall back
         # to default_zone
         default_zone = self.widget.default_timezone
-        zone = default_zone() if safe_callable(default_zone) else default_zone
+        zone = default_zone(self.widget.context)\
+            if safe_callable(default_zone) else default_zone
         ret = datetime(*map(int, value))
         if zone:
             tzinfo = pytz.timezone(zone)


Repository: plone.app.widgets
Branch: refs/heads/master
Date: 2014-04-17T14:39:25+02:00
Author: Johannes Raggam (thet) <raggam-nl at adm.at>
Commit: https://github.com/plone/plone.app.widgets/commit/dab1b298ca9bac50ca72a9a735a6d75bd8624017

fix test

Files changed:
M plone/app/widgets/tests/test_dx.py

diff --git a/plone/app/widgets/tests/test_dx.py b/plone/app/widgets/tests/test_dx.py
index 1a4ead1..fa2193f 100644
--- a/plone/app/widgets/tests/test_dx.py
+++ b/plone/app/widgets/tests/test_dx.py
@@ -324,7 +324,7 @@ def test_data_converter__timezone_callback(self):
         dt = datetime(2013, 11, 13, 10, 20)
         setattr(context, self.field.getName(), dt)
         self.widget.context = context
-        self.widget.default_timezone = lambda: 'Europe/Amsterdam'
+        self.widget.default_timezone = lambda(context): 'Europe/Amsterdam'
         tz = pytz.timezone('Europe/Amsterdam')
 
         converter = DatetimeWidgetConverter(self.field, self.widget)


Repository: plone.app.widgets
Branch: refs/heads/master
Date: 2014-04-17T14:42:44+02:00
Author: Johannes Raggam (thet) <raggam-nl at adm.at>
Commit: https://github.com/plone/plone.app.widgets/commit/f68b58519b6b5ae373ebc5e3f1f31c65a2744445

more specific changelog

Files changed:
M CHANGES.rst

diff --git a/CHANGES.rst b/CHANGES.rst
index 5f1c1d0..7131051 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,10 +4,11 @@ Changelog
 1.6.0 (unreleased)
 ------------------
 
-- Add default_timezone widget attribute to DatetimeWidget. If used and set to a
-  valid Olson DB/pytz timezone identifier or to an callback returning such, the
-  datetime object returned by the widget will be localized to that timezone.
-  This changes the timezone related behavior from version 1.4.0.
+- Add default_timezone widget attribute to the Dexterity DatetimeWidget. If
+  used and set to a valid Olson DB/pytz timezone identifier or to an callback
+  returning such, the datetime object returned by the widget will be localized
+  to that timezone.  This changes the timezone related behavior from version
+  1.4.0.
   [thet]
 
 - fix related items widget using getSource when it should use getVocabulary
@@ -114,9 +115,6 @@ Changelog
 - fix VocabularyView to accept 1-based batch pages as per doc
   [djay]
 
-- Fix the date/time value in pattern options for Archetypes DatetimeWidget.
-  [thet]
-
 - Change the start and end date fields of Products.ATContentTypes ATEvent
   types to use plone.app.widgets.
   [thet]




-------------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CHANGES.log
Type: application/octet-stream
Size: 13134 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-testbot/attachments/20140417/a3945e4d/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build.log
Type: application/octet-stream
Size: 108085 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-testbot/attachments/20140417/a3945e4d/attachment-0003.obj>


More information about the Testbot mailing list