def inner_decorator(request, *args, **kwargs): if 'location' in request.session and not override_old: return func(request, *args, **kwargs) else: ip = request.META['REMOTE_ADDR'] if 'REMOTE_ADDR' \ in request.META else None location = request.COOKIES['atlas_id'] if 'atlas_id' \ in request.COOKIES else None city = None position = None if location and location != 'no-location': position = fromstr("POINT (%s %s)" % tuple(location.split('+')), srid=4326) if ip and not position: '''if position: city = get_city(ip=ip, position=position) else:''' city = get_city(ip=ip) elif position: city = get_city(position=position) if city: request.session['location'] = {'city': city, 'position': position} return func(request, *args, **kwargs) origin = getattr(resolve(request.get_full_path()), 'url_name', None) return HttpResponseRedirect("%s%s" % (reverse('select-location'), \ ('?view=%s' % origin) if origin else ''))
def save(self): position = fromstr(self.cleaned_data['location'], srid=4326) '''if 'REMOTE_ADDR' in self.request.META: city = get_city(ip=self.request.META['REMOTE_ADDR'], position=position) else:''' city = get_city(position=position) self.request.session['location'] = {'city': city, 'position': position}
def create_task(campaign, r): t = TomTomMicroTask(poi_id=r['POI_ID']) loc = Location() # srid is the ID for the coordinate system, 4326 # specifies longitude/latitude coordinates loc.coordinates = fromstr("POINT (%s %s)" % (r['X'], r['Y']), srid=4326) city = get_city(position=loc.coordinates) if not city: logger.error('Unable to create task: %s - %s. Could not obtain city from coordinates. (%s, %s)', r['NAME'], r['POI_ID'], r['Y'], r['X']) return loc.city = city loc.country = city.country loc.save() t.title = r['NAME'] t.description = '%s %s' % (r['NAME_ALT'], r['ADDRESS']) t.category = r['CAT_NAME'] t.location = loc t.tel_1 = r['TEL_NR'] t.tel_2 = r['TEL_NR2'] t.fax = r['FAX_NR'] t.email = r['E_MAIL'] t.website = r['WEBSITE'] t.city = r['CITY'] t.suburb = r['SUBURB'] t.owner = campaign.owner t.campaign = campaign t.save() t.province.add(Province.from_str(r['PROVINCE'])) t.sites.add(Site.objects.get_current()) t.publish()