1 # |
|
2 # Copyright (c) 2008-2018 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_content.component.paragraph.interfaces import IBaseParagraph |
|
20 from pyams_content.interfaces.container import IOrderedContainer |
|
21 from zope.annotation.interfaces import IAttributeAnnotatable |
|
22 |
|
23 # import packages |
|
24 from pyams_i18n.schema import I18nTextLineField |
|
25 from zope.container.constraints import containers, contains |
|
26 from zope.interface import Interface |
|
27 from zope.schema import Bool, TextLine, Choice |
|
28 |
|
29 from pyams_content import _ |
|
30 |
|
31 |
|
32 KEYNUMBER_CONTAINER_KEY = 'pyams_content.keynumbers' |
|
33 |
|
34 |
|
35 class IKeyNumber(IAttributeAnnotatable): |
|
36 """Base key number interface""" |
|
37 |
|
38 containers('.IKeyNumberContainer') |
|
39 |
|
40 visible = Bool(title=_("Visible?"), |
|
41 description=_("Is this key number visible in front-office?"), |
|
42 required=True, |
|
43 default=True) |
|
44 |
|
45 label = I18nTextLineField(title=_('key-number-label', default="Header"), |
|
46 description=_("Small text to be displayed above number (according to selected " |
|
47 "renderer)"), |
|
48 required=False) |
|
49 |
|
50 number = TextLine(title=_("Number"), |
|
51 description=_("Key number value"), |
|
52 required=True) |
|
53 |
|
54 unit = I18nTextLineField(title=_('key-number-unit', default="Unit"), |
|
55 description=_("Displayed unit"), |
|
56 required=False) |
|
57 |
|
58 text = I18nTextLineField(title=_("Associated text"), |
|
59 description=_("The way this text will be rendered depends on presentation template"), |
|
60 required=False) |
|
61 |
|
62 |
|
63 KEYNUMBER_HIDDEN_FIELDS = ('__parent__', '__name__', 'visible') |
|
64 |
|
65 |
|
66 class IKeyNumberContainer(IOrderedContainer): |
|
67 """Key numbers container interface""" |
|
68 |
|
69 contains(IKeyNumber) |
|
70 |
|
71 def append(self, value, notify=True): |
|
72 """Append given key number to container""" |
|
73 |
|
74 def get_visible_items(self): |
|
75 """Get list of visible key numbers""" |
|
76 |
|
77 |
|
78 class IKeyNumberContainerTarget(Interface): |
|
79 """Key numbers container target interface""" |
|
80 |
|
81 |
|
82 KEYNUMBER_PARAGRAPH_TYPE = 'KeyNumbers' |
|
83 KEYNUMBER_PARAGRAPH_NAME = _("Key numbers") |
|
84 KEYNUMBER_PARAGRAPH_RENDERERS = 'PyAMS.keynumbers.renderers' |
|
85 |
|
86 |
|
87 # |
|
88 # KeyNumber paragraph |
|
89 # |
|
90 |
|
91 class IKeyNumberParagraph(IKeyNumberContainerTarget, IBaseParagraph): |
|
92 """Key numbers paragraph interface""" |
|
93 |
|
94 renderer = Choice(title=_("Key numbers template"), |
|
95 description=_("Presentation template used for key numbers"), |
|
96 vocabulary=KEYNUMBER_PARAGRAPH_RENDERERS, |
|
97 default='default') |
|