| 10 | |
| 11 | # Decorators for disallowing access based on the value of |
| 12 | # request.META['REQUEST_METHOD']. These decorators will prevent the |
| 13 | # calling of views whose operation depends on particular request |
| 14 | # methods. Note that if request.META['REQUEST_METHOD'] is not |
| 15 | # present, the views will not be called. |
| 16 | |
| 17 | from django.utils.httpwrappers import HttpResponseForbidden |
| 18 | |
| 19 | def requires_POST(view_func): |
| 20 | def _requires_POST_wrapper(request, *args, **kwargs): |
| 21 | if request.META.get('REQUEST_METHOD', None) != 'POST': |
| 22 | return HttpResponseForbidden() |
| 23 | return view_func(request, *args, **kwargs) |
| 24 | return _requires_POST_wrapper |
| 25 | |
| 26 | def requires_GET(view_func): |
| 27 | def _requires_GET_wrapper(request, *args, **kwargs): |
| 28 | if request.META.get('REQUEST_METHOD', None) != 'GET': |
| 29 | return HttpResponseForbidden() |
| 30 | return view_func(request, *args, **kwargs) |
| 31 | return _requires_GET_wrapper |