def save(self, *args, **kwargs): if not self.hash: self.hash = gen_unique_hash(self.__class__, 30) inProj = Proj(init='epsg:4326') outProj = Proj(init='epsg:3857') try: self.address_lng, self.address_lat = transform( inProj, outProj, float(self.address_lng), float(self.address_lat)) except Exception as e: print(e) # must be in correct coord system super(self.__class__, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if not self.hash: self.hash = gen_unique_hash(self.__class__, 30) inProj = Proj(init='epsg:4326') outProj = Proj(init='epsg:3857') if not self.intersection: orig_lat = self.address_lat orig_lng = self.address_lng endpoint = 'http://api.geonames.org/findNearestIntersectionOSMJSON?lat={}&lng={}&username=casap'.format( orig_lat, orig_lng) resp = requests.get(endpoint) for i in range(10): if resp is None: resp = requests.get(endpoint) else: break results = resp.json() intersection_string = '{} & {}, {}, {}'.format( results['intersection']['street2'], results['intersection']['street1'], self.city, self.province) self.intersection = intersection_string self.intersection_lng, self.intersection_lat = transform( inProj, outProj, float(results['intersection']['lng']), float(results['intersection']['lat'])) try: self.address_lng, self.address_lat = transform( inProj, outProj, float(self.address_lng), float(self.address_lat)) except Exception as e: print(e) # must be in correct coord system super(self.__class__, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if not self.hash: self.hash = gen_unique_hash(self.__class__, 30) super(self.__class__, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if not self.code: self.code = gen_unique_hash(self.__class__, 120, field_name="code") super(self.__class__, self).save(*args, **kwargs)