def clean_city(self): """City cleaner. Check that entered city match with the city regexp Fetch the associated City object """ self.city_obj = City.get_city(self.cleaned_data['city']) if self.city_obj: return self.cleaned_data['city'] raise forms.ValidationError(_("Incorrect city."))
def clean_departure(self): """Departure city cleaner Checks that the city match with the city displaying regexp. Fetch the associated city object """ self.departure_obj = City.get_city(self.cleaned_data["departure"]) if not self.departure_obj and self.cleaned_data["departure"]: raise forms.ValidationError(_("Incorrect city.")) return self.cleaned_data["departure"]
def clean_departure(self): """Departure city cleaner Checks that the city match with the city displaying regexp. Fetch the associated city object """ self.departure_obj = City.get_city(self.cleaned_data['departure']) if not self.departure_obj and self.cleaned_data['departure']: raise forms.ValidationError(_("Incorrect city.")) return self.cleaned_data['departure']
def clean_arrival(self): """Arrival city cleaner Checks that the city match with the city displaying regexp. Fetch the associated city object Fetche l'objet City associƩ. """ self.arrival_obj = City.get_city(self.cleaned_data["arrival"]) if not self.arrival_obj and self.cleaned_data["arrival"]: raise forms.ValidationError(_("Incorrect city.")) return self.cleaned_data["arrival"]
def clean_arrival(self): """Arrival city cleaner Checks that the city match with the city displaying regexp. Fetch the associated city object Fetche l'objet City associƩ. """ self.arrival_obj = City.get_city(self.cleaned_data['arrival']) if not self.arrival_obj and self.cleaned_data['arrival']: raise forms.ValidationError(_("Incorrect city.")) return self.cleaned_data['arrival']
for line in input_file: try: if re.search('^#', line): # next continue data = [d.strip() for d in line.split(';')] #print data lat = data[DATA['LAT']] if data[DATA['LAT']] != '-' else "0" lng = data[DATA['LNG']] if data[DATA['LNG']] != '-' else "0" lat = re.sub(',', '.', lat) lng = re.sub(',', '.', lng) name = smart_unicode(data[DATA['NAME']]) city = City(name=name, slug=str_slugify(name), zipcode=int(data[DATA['ZIPCODE']]), point=GEOSGeometry('POINT( %s %s )' % (lng, lat), srid=SRID_DEFAULT), insee_code=int(data[DATA['INSEECODE']]), population=0) print city, city.slug city.save() except Exception, e: print "!!!!!!!!!!!!!!!!!!!!!", line, e finally: input_file.close() print "OK\n"
try: if re.search("^#", line): # next continue data = [d.strip() for d in line.split(";")] # print data lat = data[DATA["LAT"]] if data[DATA["LAT"]] != "-" else "0" lng = data[DATA["LNG"]] if data[DATA["LNG"]] != "-" else "0" lat = re.sub(",", ".", lat) lng = re.sub(",", ".", lng) name = smart_unicode(data[DATA["NAME"]]) city = City( name=name, slug=str_slugify(name), zipcode=int(data[DATA["ZIPCODE"]]), point=GEOSGeometry("POINT( %s %s )" % (lng, lat), srid=SRID_DEFAULT), insee_code=int(data[DATA["INSEECODE"]]), population=0, ) print city, city.slug city.save() except Exception, e: print "!!!!!!!!!!!!!!!!!!!!!", line, e finally: input_file.close() print "OK\n"