|
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 from pyams_content.component.paragraph.interfaces.map import have_gis, IMapParagraph |
|
17 if have_gis: |
|
18 |
|
19 # import standard library |
|
20 |
|
21 # import interfaces |
|
22 from pyams_content.features.renderer.interfaces import IContentRenderer |
|
23 from pyams_default_theme.component.paragraph.interfaces.map import IMapParagraphDefaultRendererSettings |
|
24 from pyams_gis.interfaces.configuration import IMapConfiguration |
|
25 from pyams_gis.interfaces.utility import IMapManager |
|
26 from pyams_skin.layer import IPyAMSLayer |
|
27 |
|
28 # import packages |
|
29 from pyams_content.features.renderer.skin import BaseContentRenderer |
|
30 from pyams_gis.configuration import MapConfiguration |
|
31 from pyams_template.template import template_config |
|
32 from pyams_utils.adapter import adapter_config, get_annotation_adapter |
|
33 from pyams_utils.registry import get_utility |
|
34 from zope.interface import implementer |
|
35 from zope.schema.fieldproperty import FieldProperty |
|
36 |
|
37 from pyams_default_theme import _ |
|
38 |
|
39 |
|
40 # |
|
41 # Map paragraph default renderer settings |
|
42 # |
|
43 |
|
44 MAP_DEFAULT_RENDERER_SETTINGS_KEY = 'pyams_content.map.renderer:default' |
|
45 |
|
46 |
|
47 @implementer(IMapParagraphDefaultRendererSettings) |
|
48 class MapParagraphDefaultRendererSettings(MapConfiguration): |
|
49 """Map paragraph default renderer settings""" |
|
50 |
|
51 _use_default_map_configuration = FieldProperty(IMapParagraphDefaultRendererSettings[ |
|
52 'use_default_map_configuration']) |
|
53 |
|
54 @property |
|
55 def use_default_map_configuration(self): |
|
56 return self._use_default_map_configuration |
|
57 |
|
58 @use_default_map_configuration.setter |
|
59 def use_default_map_configuration(self, value): |
|
60 self._use_default_map_configuration = value |
|
61 |
|
62 @property |
|
63 def no_use_default_map_configuration(self): |
|
64 return not bool(self.use_default_map_configuration) |
|
65 |
|
66 @no_use_default_map_configuration.setter |
|
67 def no_use_default_map_configuration(self, value): |
|
68 self.use_default_map_configuration = not bool(value) |
|
69 |
|
70 @property |
|
71 def configuration(self): |
|
72 if self.use_default_map_configuration: |
|
73 manager = get_utility(IMapManager) |
|
74 return IMapConfiguration(manager) |
|
75 else: |
|
76 return self |
|
77 |
|
78 |
|
79 @adapter_config(context=IMapParagraph, provides=IMapParagraphDefaultRendererSettings) |
|
80 def map_paragraph_default_renderer_settings_factory(context): |
|
81 """Map paragraph default renderer settings factory""" |
|
82 return get_annotation_adapter(context, MAP_DEFAULT_RENDERER_SETTINGS_KEY, |
|
83 MapParagraphDefaultRendererSettings) |
|
84 |
|
85 |
|
86 # |
|
87 # Map paragraph default renderer |
|
88 # |
|
89 |
|
90 @adapter_config(name='default', context=(IMapParagraph, IPyAMSLayer), provides=IContentRenderer) |
|
91 @template_config(template='templates/map-default.pt', layer=IPyAMSLayer) |
|
92 class MapParagraphDefaultRenderer(BaseContentRenderer): |
|
93 """Map paragraph default renderer""" |
|
94 |
|
95 label = _("Default map renderer") |
|
96 |
|
97 settings_interface = IMapParagraphDefaultRendererSettings |
|
98 |
|
99 i18n_context_attrs = ('title', ) |