mirror of
https://github.com/nikdoof/vapemap.git
synced 2025-12-14 06:42:17 +00:00
Don't do geo lookups on import.
This commit is contained in:
@@ -36,7 +36,7 @@ class Command(BaseCommand):
|
||||
country, created = Country.objects.get_or_create(name=country)
|
||||
county, created = County.objects.get_or_create(name=county, country=country)
|
||||
addr = Address(name=name, address1=addr1, address2=addr2, address3=addr3, city=city, county=county, country=country, postcode=postcode, geo_latitude=y, geo_longitude=x)
|
||||
addr.save()
|
||||
addr.save(no_lookup=True)
|
||||
store = Store(name=name, address=addr, website=website, email=email, phone=phone)
|
||||
if website:
|
||||
store.store_type = Store.STORE_TYPE_BOTH
|
||||
|
||||
@@ -187,7 +187,8 @@ class Address(models.Model):
|
||||
return self.address_string
|
||||
|
||||
def save(self, **kwargs):
|
||||
if not self.geo_latitude and not self.geo_longitude:
|
||||
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.address_string)
|
||||
if res:
|
||||
self.geo_latitude, self.geo_longitude = res[1]
|
||||
|
||||
@@ -121,4 +121,23 @@ class StoresStoreModelTestCase(TestCase):
|
||||
|
||||
def test_chain_name(self):
|
||||
obj = Store(name='Test Store 3', address=self.addr)
|
||||
self.assertEqual(str(obj), 'Test Store 3')
|
||||
self.assertEqual(str(obj), 'Test Store 3')
|
||||
|
||||
|
||||
class StoresAddressModelTestCase(TestCase):
|
||||
|
||||
fixtures = ['countries']
|
||||
|
||||
def test_geo_lookup(self):
|
||||
country = Country.objects.get(name='United Kingdom')
|
||||
addr = Address(name='test', address1='Bridge Street', city='Warrington', country=country, postcode='WA3')
|
||||
addr.save()
|
||||
self.assertIsNotNone(addr.geo_latitude)
|
||||
self.assertIsNotNone(addr.geo_longitude)
|
||||
|
||||
def test_skip_geo_lookup(self):
|
||||
country = Country.objects.get(name='United Kingdom')
|
||||
addr = Address(name='test', address1='Bridge Street', city='Warrington', country=country, postcode='WA3')
|
||||
addr.save(no_lookup=True)
|
||||
self.assertIsNone(addr.geo_latitude)
|
||||
self.assertIsNone(addr.geo_longitude)
|
||||
Reference in New Issue
Block a user