Example #1
0
 def geocode(self, postcode):
     data = geocode(postcode)
     if data:
         self.constituency = data['constituency']
         self.location = Point(
             data['wgs84_lon'],
             data['wgs84_lat'],
         )
Example #2
0
 def clean(self):
     cleaned_data = super(ConstituencyLookupForm, self).clean()
     pcode = cleaned_data.get("postcode")
     self.location = geocode(pcode)
     if not self.location:
         raise forms.ValidationError(
             _("That postcode was not found. Please try another")
         )
Example #3
0
 def geocode(self, postcode):
     data = geocode(postcode)
     if data:
         self.constituency = data['constituency']
         self.location = Point(
             data['wgs84_lon'],
             data['wgs84_lat'],
         )
Example #4
0
    def clean(self):
        data = super(PostcodeForm, self).clean()
        if not data.get('postcode'):
            raise forms.ValidationError("Please enter a full valid UK postcode")

        postcode = self.cleaned_data['postcode']
        self.geo_data = geocode(postcode)
        if not self.geo_data or 'constituency' not in self.geo_data:
            raise forms.ValidationError("Please enter a full valid UK postcode")

        data['constituency'] = self.geo_data['constituency']
        data['wgs84_lon'] = self.geo_data['wgs84_lon']
        data['wgs84_lat'] = self.geo_data['wgs84_lat']

        return data
Example #5
0
    def clean(self):
        data = super(PostcodeForm, self).clean()
        if not data.get('postcode'):
            raise forms.ValidationError("Please enter a full valid UK postcode")

        postcode = self.cleaned_data['postcode']
        self.geo_data = geocode(postcode)
        if not self.geo_data or 'constituency' not in self.geo_data:
            raise forms.ValidationError("Please enter a full valid UK postcode")

        data['constituency'] = self.geo_data['constituency']
        data['wgs84_lon'] = self.geo_data['wgs84_lon']
        data['wgs84_lat'] = self.geo_data['wgs84_lat']

        return data
Example #6
0
 def clean_postcode(self):
     postcode = self.cleaned_data['postcode']
     self.geo_data = geocode(postcode)
     if not self.geo_data or 'constituency' not in self.geo_data:
         raise forms.ValidationError("Please enter a full valid UK postcode")
     return postcode
Example #7
0
 def clean(self):
     cleaned_data = super(ConstituencyLookupForm, self).clean()
     pcode = cleaned_data.get("postcode")
     self.location = geocode(pcode)
     if not self.location:
         raise forms.ValidationError(_("That ZIP Code was not found. Please try another"))
Example #8
0
 def geocode(self, postcode):
     data = geocode(postcode)
     if data:
         self.constituency = data["constituency"]
         self.location = Point(data["wgs84_lon"], data["wgs84_lat"],)