1 | ## Controller Script Python "validate_map" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind state=state |
---|
7 | ##bind subpath=traverse_subpath |
---|
8 | ##parameters= maplatitude='', maplongitude='', mapzoom='', maptype='' |
---|
9 | ##title= |
---|
10 | |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
13 | |
---|
14 | plone_utils = getToolByName(context, 'plone_utils') |
---|
15 | |
---|
16 | if (maplatitude and maplongitude): |
---|
17 | try: |
---|
18 | float(maplatitude) |
---|
19 | except: |
---|
20 | state.setError('maplatitude', _('Map Latitude is a decimal number')) |
---|
21 | return state.set(status='failure') |
---|
22 | try: |
---|
23 | float(maplongitude) |
---|
24 | except: |
---|
25 | state.setError('maplongitude', _('Map Longitude is a decimal number')) |
---|
26 | return state.set(status='failure') |
---|
27 | |
---|
28 | if not (-90 <= float(maplatitude) <= 90): |
---|
29 | state.setError('maplatitude', _('Map Latitude is not in bounds [-90, 90]')) |
---|
30 | |
---|
31 | if not (-180 <= float(maplongitude) <= 180): |
---|
32 | state.setError('maplongitude', _('Map Longitude is not in bounds [-180, 180]')) |
---|
33 | elif not maplatitude and maplongitude: |
---|
34 | state.setError('maplatitude', _('Provide Map Latitude or remove Map Longitude')) |
---|
35 | elif not maplongitude and maplatitude: |
---|
36 | state.setError('maplongitude', _('Provide Map Longitude or remove Map Latitude')) |
---|
37 | |
---|
38 | if state.getErrors(): |
---|
39 | plone_utils.addPortalMessage(_(u'Please correct the indicated errors.')) |
---|
40 | return state.set(status='failure') |
---|
41 | else: |
---|
42 | return state |
---|
43 | |
---|