source: products/qPloneGoogleMaps/tags/0.1.0/content/Map.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1from AccessControl import ClassSecurityInfo
2try:
3    from Products.CMFCore.permissions import ModifyPortalContent, View
4except ImportError:
5    from Products.CMFCore.CMFCorePermissions import ModifyPortalContent, View
6from Products.CMFCore.utils import getToolByName
7
8try:
9  from Products.LinguaPlone.public import *
10except ImportError:
11  from Products.Archetypes.public import *
12
13from Products.ATContentTypes.content.base import ATCTFolder, updateActions
14from Products.ATContentTypes.content.schemata import finalizeATCTSchema
15
16#from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder
17
18from Products.qPloneGoogleMaps.field import *
19from Products.qPloneGoogleMaps.config import *
20
21zoom_vocaburary = range(18)
22zoom_vocaburary.reverse()
23
24MapSchema = ATCTFolder.schema.copy() + Schema((
25    MapField('location',
26        default=None,
27        required=True,
28        validators=('isLocation',),
29        widget=MapWidget(
30            label='Map Center',
31            label_msgid='label_map_center',
32            description='Here you can choose map center point on the map by mouse clicking',
33            description_msgid='help_map_center',
34            i18n_domain='googlemaps',
35        )
36    ),
37
38    StringField('auto',
39        vocabulary=('None', 'Zoom', 'Center', 'Full'),
40        default='None',
41        widget=SelectionWidget(
42            label='Auto Control',
43            label_msgid='label_auto_control',
44            description_msgid='help_auto_control',
45            i18n_domain='googlemaps',
46            format = 'radio',
47        )
48    ),
49
50    IntegerField('height',
51        default="480",
52        required=True,
53        widget=IntegerWidget(
54            label='Height',
55            label_msgid='label_height',
56            description_msgid='help_height',
57            i18n_domain='googlemaps',
58        )
59    ),
60
61    IntegerField('zoom',
62        default=3,
63        vocabulary=zoom_vocaburary,
64        widget=SelectionWidget(
65            label='Zoom',
66            label_msgid='label_zoom',
67            description_msgid='help_zoom',
68            i18n_domain='googlemaps',
69        )
70    ),
71
72    StringField('mapControl',
73        vocabulary=('large', 'small', 'nothing'),
74        default='large',
75        widget=SelectionWidget(
76            label='Map Control',
77            label_msgid='label_map_control',
78            description_msgid='help_map_control',
79            i18n_domain='googlemaps',
80        )
81    ),
82
83    StringField('mapType',
84        vocabulary=('map', 'satellite', 'hybrid'),
85        default='hybrid',
86        widget=SelectionWidget(
87            label='Map Type',
88            label_msgid='label_map_type',
89            description_msgid='help_map_type',
90            i18n_domain='googlemaps',
91        )
92    ),
93
94    BooleanField('typeControl',
95        default=1,
96        widget=BooleanWidget(
97            label='Type Control',
98            label_msgid='label_type_control',
99            description_msgid='help_type_control',
100            i18n_domain='googlemaps',
101        )
102    ),
103
104    BooleanField('overviewControl',
105        default=1,
106        widget=BooleanWidget(
107            label='Overview Control',
108            label_msgid='label_overview_control',
109            description_msgid='help_overview_control',
110            i18n_domain='googlemaps',
111        )
112    ),
113),
114)
115
116finalizeATCTSchema(MapSchema)
117
118class Map(ATCTFolder):
119    """Google Map class"""
120
121    schema          = MapSchema
122
123    content_icon    = 'map_icon.gif'
124    portal_type     = 'Map'
125    meta_type       = 'Map'
126    archetype_name  = 'Map'
127    default_view    = 'map_view'
128    immediate_view  = 'map_view'
129    suppl_views     = ()
130    typeDescription = 'Maps Folder'
131    typeDescMsgId   = 'map_description_edit'
132
133    security        = ClassSecurityInfo()
134
135    # Get the standard actions (tabs)
136    actions = updateActions(ATCTFolder,
137        ({'id'          : 'edit',
138          'name'        : 'Edit',
139          'action'      : 'string:${object_url}/map_edit',
140          'permissions' : (ModifyPortalContent,)
141         },
142        )
143    )
144
145    #__implements__ = (ATCTFolder.__implements__, INonStructuralFolder)
146
147    allowed_content_types = ['Marker', 'Overlay']
148
149    # Make sure we get title-to-id generation when an object is created
150    _at_rename_after_creation = True
151
152    def canSetDefaultPage(self):
153        return False
154
155    security.declareProtected(View, 'geoLocation')
156    def geoLocation(self):
157        """ Return geolocation tuple """
158        return self.getLocation()
159
160    security.declareProtected(View, 'getOverlayMarkers')
161    def getOverlayMarkers(self):
162        """ Return markers of the contained overlays """
163        catalog = getToolByName(self, 'portal_catalog')
164        result = {}
165        for el in self.folderlistingFolderContents():
166            if el.portal_type == 'Overlay':
167                color = el.getMarkersColor()
168                markers =  el.getMarkers()
169            elif el.portal_type == 'Marker':
170                color = el.getColor()
171                markers = list(catalog(path='/'.join(el.getPhysicalPath())))
172            else: continue
173            result[(el.getId(),color)] = result.get(el.getId(), []) + markers
174        return result
175
176registerType(Map, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.