def process_request(self, request): """ This middleware handles redirections and error pages according to the business logic at edunext """ if not settings.FEATURES.get('USE_REDIRECTION_MIDDLEWARE', True): return None domain = request.META.get('HTTP_HOST', "") # First handle the event where a domain has a redirect target cache_key = "redirect_cache." + fasthash(domain) target = cache.get(cache_key) # pylint: disable=maybe-no-member if not target: try: target = Redirection.objects.get(domain__iexact=domain) # pylint: disable=no-member except Redirection.DoesNotExist: # pylint: disable=no-member target = '##none' cache.set( # pylint: disable=maybe-no-member cache_key, target, 5 * 60) if target != '##none': # If we are already at the target, just return if domain == target.target and request.scheme == target.scheme: # pylint: disable=no-member return None to_url = '{scheme}://{host}{path}'.format( scheme=target.scheme, # pylint: disable=no-member host=target.target, # pylint: disable=no-member path=request.path, # pylint: disable=no-member ) return HttpResponseRedirect( to_url, status=target.status, # pylint: disable=no-member ) return None
def clear_cache(sender, instance, **kwargs): # pylint: disable=unused-argument """ Clear the cached template when the model is saved """ cache_key = "redirect_cache." + fasthash(instance.domain) cache.delete(cache_key) # pylint: disable=maybe-no-member
def test_fasthash_call(self): """ Answers the question: Can we apply the fasthash method? """ test_str = "test_str" fasthash(test_str)