Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone handling #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changes
1.1 (unreleased)
----------------

- Nothing changed yet.
- Travis & egg cleanup
[tomgross]


1.0.1 (2016-02-18)
Expand Down
29 changes: 7 additions & 22 deletions collective/autopublishing/eventhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,33 +22,17 @@


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):
obj.setExpirationDate(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):
Expand Down Expand Up @@ -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()
Expand Down
52 changes: 52 additions & 0 deletions collective/autopublishing/tests/test_dates.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
zc.buildout==2.5.3
setuptools==26.1.1
zc.buildout==2.8.0
setuptools==33.1.1