|
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_gis.interfaces.configuration import IMapConfigurationTarget |
|
20 from pyams_gis.interfaces.utility import IMapManager |
|
21 from pyams_i18n.interfaces import II18n |
|
22 |
|
23 # import packages |
|
24 from pyams_utils.registry import get_utility |
|
25 from pyams_utils.request import check_request |
|
26 from pyams_utils.vocabulary import vocabulary_config |
|
27 from zope.container.folder import Folder |
|
28 from zope.interface import implementer |
|
29 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
|
30 |
|
31 |
|
32 @implementer(IMapManager, IMapConfigurationTarget) |
|
33 class MapManager(Folder): |
|
34 """Map manager utility""" |
|
35 |
|
36 |
|
37 @vocabulary_config(name='PyAMS map layers') |
|
38 class MapLayersVocabulary(SimpleVocabulary): |
|
39 """Map manager layers vocabulary""" |
|
40 |
|
41 def __init__(self, context): |
|
42 request = check_request() |
|
43 manager = get_utility(IMapManager) |
|
44 super(MapLayersVocabulary, self).__init__([SimpleTerm(layer.__name__, |
|
45 title=II18n(layer).query_attribute('title', |
|
46 request=request)) |
|
47 for layer in manager.values()]) |