source: ATGoogleMaps/tags/0.5/validator.py @ 44

Revision 44, 1.1 KB checked in by takanori, 6 years ago (diff)

add latlng field, widget, validator

Line 
1from Globals import InitializeClass
2from Products.validation import validation
3from Products.validation.interfaces.IValidator import IValidator
4from Products.CMFCore.utils import getToolByName
5
6class LatLngValidator:
7    """
8    Latitude and Longitude validator. To be used with LatLngField.
9    """
10
11    __implements__ = IValidator
12
13    def __init__(self, name, title='', description=''):
14        self.name = name
15        self.title = title
16        self.description = description
17
18    def __call__(self, value, *args, **kwargs):
19        """
20        Tests if the password values match. If value is just one string,
21        only tests size.
22        """
23
24        try:
25            latitude = float(value.latitude)
26            longitude = float(value.longitude)
27        except:
28            return 1
29
30        if latitude < -90 or latitude > 90:
31            return 'Latitude is out of range.'
32        if longitude < -180 or longitude > 180:
33            return 'Longitude is out of range.'
34
35        return 1
36
37validation.register(LatLngValidator('LatLngValidator'))
Note: See TracBrowser for help on using the repository browser.