|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_utils.interfaces.site import ISiteGenerations |
|
20 from pyams_utils.interfaces.timezone import IServerTimezone |
|
21 from zope.site.interfaces import INewLocalSite |
|
22 |
|
23 # import packages |
|
24 from persistent import Persistent |
|
25 from pyams_utils.registry import utility_config |
|
26 from pyams_utils.site import check_required_utilities |
|
27 from pyramid.events import subscriber |
|
28 from zope.container.contained import Contained |
|
29 from zope.interface import implementer |
|
30 from zope.schema.fieldproperty import FieldProperty |
|
31 |
|
32 |
|
33 @implementer(IServerTimezone) |
|
34 class ServerTimezoneUtility(Persistent, Contained): |
|
35 |
|
36 timezone = FieldProperty(IServerTimezone['timezone']) |
|
37 |
|
38 |
|
39 REQUIRED_UTILITIES = ((IServerTimezone, '', ServerTimezoneUtility, 'Server timezone'),) |
|
40 |
|
41 |
|
42 @subscriber(INewLocalSite) |
|
43 def handle_new_local_site(event): |
|
44 """Create a new ServerTimezoneUtility when a site is created""" |
|
45 site = event.manager.__parent__ |
|
46 check_required_utilities(site, REQUIRED_UTILITIES) |
|
47 |
|
48 |
|
49 @utility_config(name='PyAMS timezone checker', provides=ISiteGenerations) |
|
50 class TimezoneGenerationsChecker(object): |
|
51 """Timezone generations checker""" |
|
52 |
|
53 generation = 1 |
|
54 |
|
55 def evolve(self, site, current=None): |
|
56 """Check for required utilities""" |
|
57 check_required_utilities(site, REQUIRED_UTILITIES) |