source: products/geolocation/trunk/skins/geolocation/validate_map.vpy

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

Building directory structure

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
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
11from Products.CMFCore.utils import getToolByName
12from Products.CMFPlone import PloneMessageFactory as _
13
14plone_utils = getToolByName(context, 'plone_utils')
15
16if (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]'))
33elif  not maplatitude and maplongitude:
34        state.setError('maplatitude', _('Provide Map Latitude or remove Map Longitude'))
35elif  not maplongitude and maplatitude:
36        state.setError('maplongitude', _('Provide Map Longitude or remove Map Latitude'))
37
38if state.getErrors():
39    plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
40    return state.set(status='failure')
41else:
42    return state
43
Note: See TracBrowser for help on using the repository browser.