From 551e09d211c43dcf756b10cfae47ae6c8a4dd7ce Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 23 May 2017 06:45:11 +0000 Subject: [PATCH 1/3] Handle timezone for effective and expires date --- CHANGES.rst | 3 ++- collective/autopublishing/eventhandler.py | 29 ++++++----------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f168fe7..67747cb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,8 @@ Changes 1.1 (unreleased) ---------------- -- Nothing changed yet. +- Travis & egg cleanup + [tomgross] 1.0.1 (2016-02-18) diff --git a/collective/autopublishing/eventhandler.py b/collective/autopublishing/eventhandler.py index f78474d..629faba 100644 --- a/collective/autopublishing/eventhandler.py +++ b/collective/autopublishing/eventhandler.py @@ -3,6 +3,7 @@ from zope.component import ComponentLookupError, getUtility from plone.registry.interfaces import IRegistry +from plone.app.event.base import default_timezone from plone import api from Products.CMFCore.WorkflowCore import WorkflowException @@ -21,16 +22,8 @@ def getExpirationDate(obj): - # Archetypes - try: - date = obj.getExpirationDate() - return date - # Handle dexterity - except AttributeError: - date = obj.expires() - return date - - return None + tz = default_timezone(context=obj) + return obj.ExpirationDate(zone=tz) def setExpirationDate(obj, date): @@ -38,16 +31,8 @@ def setExpirationDate(obj, date): def getEffectiveDate(obj): - # Archetypes - try: - date = obj.getEffectiveDate() - return date - # Handle dexterity - except AttributeError: - date = obj.effective - return date - - return None + tz = default_timezone(context=obj) + return obj.EffectiveDate(zone=tz) def assemble_mail_text(record): @@ -106,8 +91,8 @@ def autopublish_handler(event): def handle_publishing(context, settings, dry_run=True, log=True): - ''' - ''' + """ Handle the publishing action for context + """ catalog = api.portal.get_tool(name='portal_catalog') wf = api.portal.get_tool(name='portal_workflow') now = context.ZopeTime() From f03567f49ed78712fb4b6dec918d54ae1b493715 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 23 May 2017 06:45:24 +0000 Subject: [PATCH 2/3] Add test for timezone handling --- collective/autopublishing/tests/test_dates.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 collective/autopublishing/tests/test_dates.py diff --git a/collective/autopublishing/tests/test_dates.py b/collective/autopublishing/tests/test_dates.py new file mode 100644 index 0000000..81e3c55 --- /dev/null +++ b/collective/autopublishing/tests/test_dates.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +from collective.autopublishing.eventhandler import autopublish_handler +from collective.autopublishing.eventhandler import transition_handler +from collective.autopublishing.tests.layer import C_AUTOPUBLISHING_LAYER +from Products.DCWorkflow.Transitions import TransitionDefinition +from DateTime import DateTime +from plone.app.event.testing import set_env_timezone +from plone.app.event.testing import set_timezone +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID +from plone import api + +import unittest + +TZ = 'Europe/Zurich' + + +class DummyTransitionEvent(object): + """ A dummy transition event with just object and transition + """ + + def __init__(self, obj, transition): + self.object = obj + self.transition = transition + + +class TimeZoneTest(unittest.TestCase): + + layer = C_AUTOPUBLISHING_LAYER + + def setUp(self): + print(set_env_timezone(TZ)) + print(set_timezone(TZ)) + portal = self.layer['portal'] + setRoles(portal, TEST_USER_ID, ['Manager', ]) + self.doc1 = api.content.create(portal, 'Document', title='Document 1') + + def test_effective_tz(self): + retract = TransitionDefinition('publish') + retract_event = DummyTransitionEvent(self.doc1, transition=retract) + effective = DateTime(2016, 5, 5) + self.doc1.setEffectiveDate(effective) + transition_handler(retract_event) + print(self.doc1.EffectiveDate()) + + def X_test_expires_tz(self): + effective = DateTime(2016, 5, 5) + self.doc1.setEffectiveDate(effective) + autopublish_handler(self.event1) + print(self.doc1.EffectiveDate()) + +# EOF From b33d04118a166253ea3d4184b032f861e865ff54 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 23 May 2017 07:20:35 +0000 Subject: [PATCH 3/3] Update setuptools and buildout versions to make tests pass on Plone 5.1 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0e96d78..14e3719 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -zc.buildout==2.5.3 -setuptools==26.1.1 +zc.buildout==2.8.0 +setuptools==33.1.1