def save(self, **kwargs): no_lookup = kwargs.pop('no_lookup', None) if not no_lookup and not self.geo_latitude and not self.geo_longitude: res = caching_geo_lookup(self.full_address) if res: self.geo_latitude, self.geo_longitude = res[1] return super(Address, self).save(**kwargs)
def test_caching_geo_lookup(self): from stores.utils import caching_geo_lookup from django.core.cache import cache addr = "Bridge Street, Warrington, WA3" slug = addr.lower().replace(',', '').replace(' ', '-') print slug lat, lng = caching_geo_lookup(addr) self.assertNotEqual(lat, '') self.assertNotEqual(lng, '') self.assertIsNotNone(cache.get('geo_%s' % slug, None))