def get(self, request, *args, **kwargs): # Return appropriate status code on invalid requests try: thumbnail = get_thumbnail(**self.kwargs) except ThumbnailError as e: # FIXME: Handle SourceDoesNotExist with a different, # cacheable response to keep bogus URLs from hitting # the backend all the time. return http.HttpResponse(status=e.status, content=e) # Make only one worker busy on this thumbnail by managing a lock if cache.get(thumbnail.key) is None: try: cache.set(thumbnail.key, True, self.lock_timeout) thumbnail.generate() finally: cache.delete(thumbnail.key) # Internal redirect to the generated file return self.sendfile(request, thumbnail) # Return 404 while there's a lock. Also, make sure user agents and # proxies don't cache this intermediate response. response = http.HttpResponse(status=404) add_never_cache_headers(response) return response
def dispatch(self, request, *args, **kwargs): # We put the code inline instead of using method_decorator() otherwise # kwargs is interpreted as parameters in sensitive_post_parameters. request.sensitive_post_parameters = '__ALL__' response = super(RegistrationPasswordConfirmBaseView, self).dispatch( request, *args, **kwargs) add_never_cache_headers(response) return response
def dispatch(self, request, *args, **kwargs): # We put the code inline instead of using method_decorator() otherwise # kwargs is interpreted as parameters in sensitive_post_parameters. request.sensitive_post_parameters = '__ALL__' response = super(RegistrationPasswordConfirmBaseView, self).dispatch( request, *args, **kwargs) add_never_cache_headers(response) return response
def dispatch(self, request, *args, **kwargs): if is_authenticated(request): auth_logout(request) # We put the code inline instead of using method_decorator() otherwise # kwargs is interpreted as parameters in sensitive_post_parameters. request.sensitive_post_parameters = '__ALL__' response = super(ActivationBaseView, self).dispatch(request, *args, **kwargs) add_never_cache_headers(response) return response
def dispatch(self, request, *args, **kwargs): if is_authenticated(request): auth_logout(request) # We put the code inline instead of using method_decorator() otherwise # kwargs is interpreted as parameters in sensitive_post_parameters. request.sensitive_post_parameters = '__ALL__' response = super(ActivationBaseView, self).dispatch( request, *args, **kwargs) add_never_cache_headers(response) return response
def decorator(*args, **kwargs): try: REQUEST = args[0].REQUEST except: REQUEST = args[1].REQUEST objects = func(*args, **kwargs) if isinstance(objects, HttpResponse): return objects try: data = json.dumps(objects) if 'callback' in REQUEST: # a JSONP response! data = '%s(%s);' % (REQUEST['callback'], data) return HttpResponse(data, "text/javascript") except: data = json.dumps(str(objects)) response = HttpResponse(data, "application/json") add_never_cache_headers(response) return response