root/qPloneGoogleMaps/trunk/validator.py

Revision 396 (checked in by piv, 2 years ago)

added map widget, ...

  • Property svn:eol-style set to native
Line 
1 from Products.validation.interfaces import ivalidator
2
3 class MapFieldValidator:
4
5     __implements__ = (ivalidator,)
6
7     def __init__(self, name):
8         self.name = name
9
10     def __call__(self, value, *args, **kwargs):
11         if value == None: return 1
12         if value == ('', ''): return """ This field is required. """
13         try:
14             lat, lng = value
15         except: return """ Validation failed. Unexpected field value. """
16         try:
17             lat = float(lat)
18             lng = float(lng)
19         except: return """ Validation failed. Coordinates must be an decimal numbers. """
20         if not (-90  <= lat <= 90 ): return """ Validation failed. Latitude not in bounds [-90, 90]. """
21         if not (-180 <= lng <= 180): return """ Validation failed. Longitude not in bounds [-180, 180]. """
22         return 1
Note: See TracBrowser for help on using the browser.