Updated links to the "project website" and made the READMEs consistent with the docs.
[philo.git] / philo / contrib / penfield / middleware.py
1 from django.http import HttpResponse
2 from django.utils.decorators import decorator_from_middleware
3
4 from philo.contrib.penfield.exceptions import HttpNotAcceptable
5
6
7 class HttpNotAcceptableMiddleware(object):
8         """Middleware to catch :exc:`~philo.contrib.penfield.exceptions.HttpNotAcceptable` and return an :class:`HttpResponse` with a 406 response code. See :rfc:`2616`."""
9         def process_exception(self, request, exception):
10                 if isinstance(exception, HttpNotAcceptable):
11                         return HttpResponse(status=406)
12
13
14 http_not_acceptable = decorator_from_middleware(HttpNotAcceptableMiddleware)