def inner_decorator(request, *args, **kwargs): if 'location' in request.session and not override_old: return func(request, *args, **kwargs) else: locate(request) if 'location' in request.session: 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 set_location(request): # force the location to be overridden if 'location' in request.session: del request.session['location'] locate(request) if 'location' in request.session: return HttpResponse(str(request.session['location']['city'])) if 'REMOTE_ADDR' in request.META: if 'atlas_id' in request.COOKIES: return HttpResponseBadRequest('Client cannot be located using IP %s and location %s' % (request.META['REMOTE_ADDR'], request.COOKIES['atlas_id'])) return HttpResponseBadRequest('Client cannot be located using IP %s' % request.META['REMOTE_ADDR']) elif 'atlas_id' in request.COOKIES: return HttpResponseBadRequest('Client cannot be located using location %s' % request.COOKIES['atlas_id']) return HttpResponseBadRequest('Client cannot be located without IP or location cookie')