|
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 from persistent import Persistent |
|
18 |
|
19 # import interfaces |
|
20 from pyams_content.component.illustration.interfaces import IIllustration |
|
21 from pyams_content.component.illustration.zmi.interfaces import IIllustrationWithZoomSettings |
|
22 from pyams_i18n.interfaces import II18n |
|
23 from pyams_content.features.renderer.interfaces import IContentRenderer |
|
24 from pyams_skin.layer import IPyAMSLayer |
|
25 from zope.annotation.interfaces import IAnnotations |
|
26 |
|
27 # import packages |
|
28 from pyams_content.features.renderer.zmi import BaseContentRenderer |
|
29 from pyams_template.template import template_config |
|
30 from pyams_utils.adapter import adapter_config |
|
31 from zope.interface import implementer |
|
32 from zope.location import locate, Location |
|
33 from zope.schema.fieldproperty import FieldProperty |
|
34 |
|
35 from pyams_content import _ |
|
36 |
|
37 |
|
38 # |
|
39 # Illustration renderers |
|
40 # |
|
41 |
|
42 class BaseIllustrationRenderer(BaseContentRenderer): |
|
43 """Base illustration renderer""" |
|
44 |
|
45 language = None |
|
46 |
|
47 def update(self): |
|
48 i18n = II18n(self.context) |
|
49 if self.language: |
|
50 self.legend = i18n.get_attribute('alt_title', self.language, request=self.request) |
|
51 else: |
|
52 self.legend = i18n.query_attribute('alt_title', request=self.request) |
|
53 |
|
54 |
|
55 @adapter_config(name='hidden', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer) |
|
56 class HiddenIllustrationRenderer(BaseIllustrationRenderer): |
|
57 """Hidden illustration renderer""" |
|
58 |
|
59 label = _("Hidden illustration") |
|
60 weight = -999 |
|
61 |
|
62 def render(self): |
|
63 return '' |
|
64 |
|
65 |
|
66 @adapter_config(name='default', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer) |
|
67 @template_config(template='templates/renderer-default.pt', layer=IPyAMSLayer) |
|
68 class DefaultIllustrationRenderer(BaseIllustrationRenderer): |
|
69 """Default illustration renderer""" |
|
70 |
|
71 label = _("Centered illustration") |
|
72 weight = 1 |
|
73 |
|
74 |
|
75 @adapter_config(name='left+zoom', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer) |
|
76 @template_config(template='templates/renderer-left.pt', layer=IPyAMSLayer) |
|
77 class LeftIllustrationWithZoomRenderer(BaseIllustrationRenderer): |
|
78 """Illustration renderer with small image and zoom""" |
|
79 |
|
80 label = _("Small illustration on the left with zoom") |
|
81 weight = 2 |
|
82 |
|
83 target_interface = IIllustrationWithZoomSettings |
|
84 |
|
85 |
|
86 @adapter_config(name='right+zoom', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer) |
|
87 @template_config(template='templates/renderer-right.pt', layer=IPyAMSLayer) |
|
88 class RightIllustrationWithZoomRenderer(BaseIllustrationRenderer): |
|
89 """Illustration renderer with small image and zoom""" |
|
90 |
|
91 label = _("Small illustration on the right with zoom") |
|
92 weight = 3 |
|
93 |
|
94 target_interface = IIllustrationWithZoomSettings |
|
95 |
|
96 |
|
97 # |
|
98 # Illustration renderer with zoom settings |
|
99 # |
|
100 |
|
101 ILLUSTRATION_ZOOM_RENDERER_SETTINGS_KEY = 'pyams_content.illustration.renderer:zoom' |
|
102 |
|
103 |
|
104 @implementer(IIllustrationWithZoomSettings) |
|
105 class IllustrationZoomSettings(Persistent, Location): |
|
106 """Illustration zoom renderer settings""" |
|
107 |
|
108 zoom_on_click = FieldProperty(IIllustrationWithZoomSettings['zoom_on_click']) |
|
109 |
|
110 |
|
111 @adapter_config(context=IIllustration, provides=IIllustrationWithZoomSettings) |
|
112 def IllustrationWithZoomSettingsFactory(context): |
|
113 """Illustration zoom renderer settings factory""" |
|
114 annotations = IAnnotations(context) |
|
115 settings = annotations.get(ILLUSTRATION_ZOOM_RENDERER_SETTINGS_KEY) |
|
116 if settings is None: |
|
117 settings = annotations[ILLUSTRATION_ZOOM_RENDERER_SETTINGS_KEY] = IllustrationZoomSettings() |
|
118 locate(settings, context) |
|
119 return settings |