|
1 ### -*- coding: utf-8 -*- #################################################### |
|
2 ############################################################################## |
|
3 # |
|
4 # Copyright (c) 2008-2010 Thierry Florac <tflorac AT ulthar.net> |
|
5 # All Rights Reserved. |
|
6 # |
|
7 # This software is subject to the provisions of the Zope Public License, |
|
8 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
12 # FOR A PARTICULAR PURPOSE. |
|
13 # |
|
14 ############################################################################## |
|
15 |
|
16 __docformat__ = "restructuredtext" |
|
17 |
|
18 # import standard packages |
|
19 import pytz |
|
20 |
|
21 # import Zope3 interfaces |
|
22 from zope.schema.interfaces import IChoice, IVocabularyFactory |
|
23 |
|
24 # import local interfaces |
|
25 |
|
26 # import Zope3 packages |
|
27 from zope.interface import implements, classProvides |
|
28 from zope.schema import Choice |
|
29 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary |
|
30 |
|
31 # import local packages |
|
32 |
|
33 |
|
34 class TimezonesVocabulary(SimpleVocabulary): |
|
35 |
|
36 classProvides(IVocabularyFactory) |
|
37 |
|
38 def __init__(self, *args, **kw): |
|
39 terms = [SimpleTerm(t, t, t) for t in pytz.all_timezones] |
|
40 super(TimezonesVocabulary, self).__init__(terms) |
|
41 |
|
42 |
|
43 class ITimezone(IChoice): |
|
44 """Marker interface for timezone field""" |
|
45 |
|
46 |
|
47 class Timezone(Choice): |
|
48 """Timezone choice field""" |
|
49 |
|
50 implements(ITimezone) |
|
51 |
|
52 def __init__(self, **kw): |
|
53 if 'vocabulary' in kw: |
|
54 kw.pop('vocabulary') |
|
55 if 'default' not in kw: |
|
56 kw['default'] = u'GMT' |
|
57 super(Timezone, self).__init__(vocabulary='ZTFY timezones', **kw) |