Last change
on this file since 940 was
1,
checked in by myroslav, 19 years ago
|
Building directory structure
|
-
Property svn:eol-style set to
native
|
File size:
831 bytes
|
Rev | Line | |
---|
[1] | 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 repository browser.