Ejemplo n.º 1
0
 def clean(self):
     # if errors in data, cleaned_data may be wiped, and/or fields not available
     cleaned_data = self.cleaned_data
     data = cleaned_data.get('location', '').strip()
     self.loc_found = get_location(data)
     if not self.loc_found:
         increment_failed_locations(data)
         raise forms.ValidationError("Location not found.")
     return cleaned_data
Ejemplo n.º 2
0
 def clean(self):
     # if errors in data, cleaned_data may be wiped, and/or fields not available
     cleaned_data = self.cleaned_data
     data = cleaned_data.get("location", "").strip()
     self.loc_found = get_location(data)
     if not self.loc_found:
         increment_failed_locations(data)
         raise forms.ValidationError("Location not found.")
     return cleaned_data
Ejemplo n.º 3
0
 def clean_new_location(self):
     data = self.cleaned_data['new_location']
     if data:
         loc_ids = data.split(',')
         locs = list(Location.objects(id__in=loc_ids))
         new_locs = [l for l in loc_ids if l not in [loc.id for loc in locs]]
         new_locs_errors = []
         for new_loc in new_locs:
             loc = Location.create_from(new_loc)
             if loc:
                 locs.append(loc)
             else:
                 increment_failed_locations(new_loc)
                 new_locs_errors.append(new_loc)
         self.locations = locs
         if new_locs_errors:
             raise forms.ValidationError('Could not find these locations: %s' % ', '.join(new_locs_errors))
     return data
Ejemplo n.º 4
0
 def clean_new_location(self):
     data = self.cleaned_data['new_location']
     if data:
         loc_ids = data.split(',')
         locs = list(Location.objects(id__in=loc_ids))
         new_locs = [l for l in loc_ids if l not in [loc.id for loc in locs]]
         new_locs_errors = []
         for new_loc in new_locs:
             loc = Location.create_from(new_loc)
             if loc:
                 locs.append(loc)
             else:
                 increment_failed_locations(new_loc)
                 new_locs_errors.append(new_loc)
         self.locations = locs
         if new_locs_errors:
             raise forms.ValidationError('Could not find these locations: %s' % ', '.join(new_locs_errors))
     return data
Ejemplo n.º 5
0
    def clean(self):
        # if errors in data, cleaned_data may be wiped, and/or fields not available
        cleaned_data = self.cleaned_data
        data = cleaned_data.get('post_code', '').strip()
        kwords = cleaned_data.get('kwords', '').strip()
        boost_location = cleaned_data.get('boost_location', '') or settings.SOLR_LOC_BOOST_DEFAULT
        event = cleaned_data.get('events_only')

        if not(data or kwords):
            raise forms.ValidationError("Please enter a location and/or some text and try again.")

        loc, self.results = find_by_place_or_kwords(data, kwords, boost_location, event='*' if event else None)
        if loc:
            self.centre = {'loc': Location.objects.get(id=loc['_id']), 'location': loc['lat_lon'] }
        elif data:
            increment_failed_locations(data)
            raise forms.ValidationError("Could not find a location from what you've typed- try again?")
            
        return cleaned_data
Ejemplo n.º 6
0
    def clean(self):
        # if errors in data, cleaned_data may be wiped, and/or fields not available
        cleaned_data = self.cleaned_data
        data = cleaned_data.get('post_code', '').strip()
        kwords = cleaned_data.get('kwords', '').strip()
        boost_location = cleaned_data.get('boost_location', '') or settings.SOLR_LOC_BOOST_DEFAULT
        event = cleaned_data.get('events_only')

        if not(data or kwords):
            raise forms.ValidationError("Please enter a location and/or some text and try again.")

        loc, self.results = find_by_place_or_kwords(data, kwords, boost_location, event='*' if event else None)
        if loc:
            self.centre = {'loc': Location.objects.get(id=loc['_id']), 'location': loc['lat_lon'] }
        elif data:
            increment_failed_locations(data)
            raise forms.ValidationError("Could not find a location from what you've typed- try again?")

        return cleaned_data