Simple View Middleware to allow a Prefilter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from sys import modules

class ViewModulePrefilter(object):
    """Simple Django View Middleware to allow a prefilter function in view modules"""
    def process_view(self, request, view_func, view_args, view_kwargs):
        module = modules[view_func.__module__]
        prefilter_func_name = 'prefilter'
        if hasattr(module, prefilter_func_name):
            prefilter_func = getattr(module, prefilter_func_name)
            response = prefilter_func(request, view_func, view_args, view_kwargs)
            if response:
                return response

More like this

  1. JSON View Decorator by bryanpieper 1 year, 7 months ago
  2. Middleware to resolve current URL to module and view by kuchin 1 year, 6 months ago
  3. X-Sendfile static file serve view by dokterbob 1 year, 4 months ago
  4. SSL Redirect Middleware and testing by willhardy 3 years, 7 months ago
  5. Preferred Domain decorator function. by jamiecURLe 3 years, 2 months ago

Comments

(Forgotten your password?)