diff -r 16d47bd81d84 -r 3f89629b9e54 src/pyams_utils/timezone/utility.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_utils/timezone/utility.py Thu Feb 19 00:46:48 2015 +0100 @@ -0,0 +1,57 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_utils.interfaces.site import ISiteGenerations +from pyams_utils.interfaces.timezone import IServerTimezone +from zope.site.interfaces import INewLocalSite + +# import packages +from persistent import Persistent +from pyams_utils.registry import utility_config +from pyams_utils.site import check_required_utilities +from pyramid.events import subscriber +from zope.container.contained import Contained +from zope.interface import implementer +from zope.schema.fieldproperty import FieldProperty + + +@implementer(IServerTimezone) +class ServerTimezoneUtility(Persistent, Contained): + + timezone = FieldProperty(IServerTimezone['timezone']) + + +REQUIRED_UTILITIES = ((IServerTimezone, '', ServerTimezoneUtility, 'Server timezone'),) + + +@subscriber(INewLocalSite) +def handle_new_local_site(event): + """Create a new ServerTimezoneUtility when a site is created""" + site = event.manager.__parent__ + check_required_utilities(site, REQUIRED_UTILITIES) + + +@utility_config(name='PyAMS timezone checker', provides=ISiteGenerations) +class TimezoneGenerationsChecker(object): + """Timezone generations checker""" + + generation = 1 + + def evolve(self, site, current=None): + """Check for required utilities""" + check_required_utilities(site, REQUIRED_UTILITIES)