1 | from ZPublisher import HTTPRequest |
---|
2 | from AccessControl import ClassSecurityInfo |
---|
3 | from Products.Archetypes import atapi |
---|
4 | from Products.Archetypes.Widget import TypesWidget |
---|
5 | from Products.Archetypes.Registry import registerField, registerWidget |
---|
6 | |
---|
7 | |
---|
8 | class MapWidget(TypesWidget): |
---|
9 | |
---|
10 | _properties = TypesWidget._properties.copy() |
---|
11 | _properties.update({ |
---|
12 | 'type': 'map', |
---|
13 | 'macro': 'map_widget', |
---|
14 | }) |
---|
15 | |
---|
16 | security = ClassSecurityInfo() |
---|
17 | |
---|
18 | security.declarePublic('process_form') |
---|
19 | def process_form(self, instance, field, form, empty_marker=None, emptyReturnsMarker=False): |
---|
20 | """ create tuple from latitude and longitude """ |
---|
21 | latitude = form.get('%s_latitude' % field.getName(), empty_marker) |
---|
22 | longitude = form.get('%s_longitude' % field.getName(), empty_marker) |
---|
23 | try: |
---|
24 | latitude = float(latitude) |
---|
25 | longitude = float(longitude) |
---|
26 | except: pass |
---|
27 | return (latitude, longitude), {} |
---|
28 | |
---|
29 | |
---|
30 | class MapField(atapi.ObjectField): |
---|
31 | |
---|
32 | _properties = atapi.ObjectField._properties.copy() |
---|
33 | _properties.update({ |
---|
34 | 'widget' : MapWidget, |
---|
35 | 'default' : None, |
---|
36 | }) |
---|
37 | |
---|
38 | registerWidget( |
---|
39 | MapWidget, |
---|
40 | title='Map Coordinates', |
---|
41 | used_for=('Products.field.MapField',) |
---|
42 | ) |
---|
43 | |
---|
44 | registerField( |
---|
45 | MapField, |
---|
46 | title="MapField", |
---|
47 | description=("Field that can store coordinate information (longitude, latitude)" |
---|
48 | "on the map") |
---|
49 | ) |
---|