def save(self, *args, **kwargs): #if total votes is not None, then we calc our rating if self.rating_total_votes is not None and self.rating_total_votes > 0: self.rating = ( float(self.rating_sum) / float(self.rating_total_votes) ) self.address = clean_address(self.address) # if self.address is not None: # try: # #try to geocode # place, ( lat, lng ) = g.geocode( self.address + "," + self.city + " " + self.state, exactly_one=False )[0] # #if lat and lgn aren't blank # if ( lng is not None or lng != "" ) and ( lat is not None or lng != "" ): # #set geom for our address # self.geom = fromstr( 'POINT(' + str(lng) + " " + str(lat) +')', srid = 4326 ) # self.geocoder = "Google" # except: # #if errors are thrown then we throw an validation error # raise ValidationError super(Restaurant, self).save(*args, **kwargs) # Call the "real" save() method.
noncritical_violations_text += str( soup ) + ", " #checking for a comma to remove if noncritical_violations_text.strip()[-1:] == ",": noncritical_violations_text = noncritical_violations_text.strip()[:-1] #print "noncritical_violations_text = " + str( noncritical_violations_text ) print "-----------------------" #now that we have the info broke out.. lets try to match it to a restaurant. print "name = " + name print "address = " + address print "trying to find an entry for this restaurant" #query for the restaurant based on name and address. #i need to come up with a secondary way of searching for the restaurant as well. too easy to miss the restaurant due to slight changes. temp_restaurant,created = Restaurant.objects.get_or_create(name__iexact=name,address__iexact=clean_address(address)) #get all the restaurants that match the name a filter through them #if we create the restaurant, we need to set some vars if created is True: print "*********************************** CREATED NEW RESTAURANT **********************************" #setting various vars for the restaurant temp_restaurant.name = name temp_restaurant.address = clean_address(address) temp_restaurant.city = city temp_restaurant.state = "MO" temp_restaurant.hours = None temp_restaurant.geocoder = None temp_restaurant.active = True #get the geometry print "geocoding restaurant since it isn't tagged" try: