def test_near_query(self): test_place = Place.objects.create( name='Wausau', city='Wausau', state='WI' ) location = geocode('54401') # lookup using the location tuple and explicit distance nearby = Place.objects.near(location.location, 20) self.assertEqual(len(nearby), 1) self.assertTrue(test_place in nearby) # lookup with location object and explicit distance nearby = Place.objects.near(location, 20) self.assertEqual(len(nearby), 1) self.assertTrue(test_place in nearby) # lookup with no distance info should fail self.assertRaises(ValueError, Place.objects.near, location) # lookup with distance attached but not passed explicitly location.nearby_distance = 20 nearby = Place.objects.near(location) self.assertEqual(len(nearby), 1) self.assertTrue(test_place in nearby)
def test_place_creation(self): # make sure geocode is working assert(geocode('54403').latitude) # create a Place from address; location should be added automatically place1 = Place.objects.create( name='MWC Wausau', address='557 Scott St', city='Wausau', state='WI', zip_code='54403' ) self.assertTrue(place1.latitude) self.assertTrue(place1.longitude) # create a Place with no address but location; should not be changed place2 = Place.objects.create( name='nowhere in particular', location=(45, 45) ) self.assertFalse(place2.address) self.assertEqual(place2.location, (45, 45)) # create a Place with address and location, should not be changed place3 = Place.objects.create( name='MWC Wausau with wrong location', address='557 Scott St', city='Wausau', state='WI', zip_code='54403', location=(-45, -45) ) self.assertEqual(place3.address, '557 Scott St') self.assertEqual(place3.location, (-45, -45))
def render(self, context): try: request = context['request'] zip_code = get_current_site(request).profile.zip_code except KeyError: zip_code = settings.DEFAULT_ZIP_CODE location = geocode(zip_code).location (places, current, upcoming) = get_cancellations(location, 80) context[self.var_name] = len(current) + len(upcoming) return ''
def _get_request_location(request): location = geolocate_request(request) # need to make sure the location has a ZIP for intellicast if not location.zip_code: try: zip_code = get_current_site(request).profile.zip_code except AttributeError: zip_code = settings.DEFAULT_ZIP_CODE else: if not zip_code: zip_code = settings.DEFAULT_ZIP_CODE location = geocode(zip_code) location.zip_code = zip_code return location
def save(self, *args, **kwargs): if not self.city and not self.state and not self.zip_code: super(Place, self).save(*args, **kwargs) return '' if self.city == ' ' and self.state == ' ' and self.zip_code == ' ': super(Place, self).save(*args, **kwargs) return '' geoloc = geocode(self.full_address) self.location = geoloc.location if not self.city: self.city = geoloc.city if not self.state: self.state = geoloc.state if not self.zip_code: self.zip_code = geoloc.zip_code super(Place, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if ( self.full_address and ( self.location == (None, None) or getattr(settings, 'LOCI_ALWAYS_SET_LOCATION', False) ) ): geoloc = geocode(self.full_address) self.location = geoloc.location if not self.city: self.city = geoloc.city if not self.state: self.state = geoloc.state if not self.zip_code: self.zip_code = geoloc.zip_code super(Place, self).save(*args, **kwargs)