source: ATGoogleMaps/tags/0.5.2/field.py @ 59

Revision 59, 1.7 KB checked in by takanori, 6 years ago (diff)

latlng フィールドを辞書型に変更

Line 
1from Globals import InitializeClass
2from AccessControl import ClassSecurityInfo
3from Products.Archetypes.Registry import registerField
4from Products.Archetypes.Field import ObjectField, Field
5from Products.ATGoogleMaps.widget import LatLngWidget
6
7import validator
8
9class LatLngField(ObjectField):
10    """A field that store latitude and longitude value"""
11    __implements__ = ObjectField.__implements__
12
13    _properties = Field._properties.copy()
14    _properties.update({
15        'type': 'latlng',
16        'default': {},
17        'size': 12,
18        'default': None,
19        'widget': LatLngWidget,
20        'validators': ('LatLngValidator'),
21        })
22
23    security  = ClassSecurityInfo()
24       
25    security.declarePrivate('validate_required')
26    def validate_required(self, instance, value, errors):
27        try:
28            float(value.latitude)
29            float(value.longitude)
30        except (ValueError, TypeError):
31            result = False
32        else:
33            result = True
34        return ObjectField.validate_required(self, instance, result, errors)
35
36    security.declarePrivate('get')
37    def get(self, instance, **kwargs):
38        return ObjectField.get(self, instance, **kwargs)
39
40    security.declarePrivate('set')
41    def set(self, instance, value, **kwargs):
42        if type(value) != type({}) and hasattr(value, 'keys'):
43            new_value = {}
44            new_value.update(value)
45            value = new_value
46           
47        ObjectField.set(self, instance, value, **kwargs)
48
49InitializeClass(LatLngField)
50
51registerField(LatLngField,
52              title="LatLng",
53              description="Used to store longitude and longitude.",
54              )
55
Note: See TracBrowser for help on using the repository browser.