#26626: Update decorator_from_middleware to work with new-style middleware -------------------------------+-------------------------------------- Reporter: Tim Graham | Owner: Carl Meyer Type: New feature | Status: assigned Component: HTTP handling | Version: master Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+--------------------------------------
Comment (by David Svenson): The following function takes a new-style middleware class and makes a view decorator out of it. It's used in code that me and @pelme are working on, though not as a decorator. {{{ def decorator_from_middleware_new(new_middleware_cls): def view_decorator(view_function): def view(request, *args, **kwargs): def get_response(request_inner): assert request is request_inner try: return view_function(request, *args, **kwargs) except Exception as e: new_middleware.process_exception(request, e) return HttpResponseServerError() new_middleware = new_middleware_cls(get_response) return new_middleware(request) return view return view_decorator }}} -- Ticket URL: <https://code.djangoproject.com/ticket/26626#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.579d22b1b974ef6a3c382f8518753be9%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.