Ticket #15637: add-require-safe-http-decorator.patch

File add-require-safe-http-decorator.patch, 2.3 KB (added by Aymeric Augustin, 14 years ago)
  • docs/topics/http/decorators.txt

     
    3636
    3737Decorator to require that a view only accept the POST method.
    3838
     39.. function:: require_safe()
     40
     41Decorator to require that a view only accept the GET and HEAD methods. It is similar to require_GET, but does not break software relying on HEAD requests, like link checkers.
     42
     43
    3944Conditional view processing
    4045===========================
    4146
  • tests/regressiontests/decorators/tests.py

     
    1010from django.utils.decorators import method_decorator
    1111from django.utils.functional import allow_lazy, lazy, memoize
    1212from django.utils.unittest import TestCase
    13 from django.views.decorators.http import require_http_methods, require_GET, require_POST
     13from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe
    1414from django.views.decorators.vary import vary_on_headers, vary_on_cookie
    1515from django.views.decorators.cache import cache_page, never_cache, cache_control
    1616
     
    2424fully_decorated = require_http_methods(["GET"])(fully_decorated)
    2525fully_decorated = require_GET(fully_decorated)
    2626fully_decorated = require_POST(fully_decorated)
     27fully_decorated = require_safe(fully_decorated)
    2728
    2829# django.views.decorators.vary
    2930fully_decorated = vary_on_headers('Accept-language')(fully_decorated)
  • django/views/decorators/http.py

     
    5252require_POST = require_http_methods(["POST"])
    5353require_POST.__doc__ = "Decorator to require that a view only accept the POST method."
    5454
     55require_safe = require_http_methods(["GET", "HEAD"])
     56require_safe.__doc__ = "Decorator to require that a view only accept the GET and HEAD methods."
     57
    5558def condition(etag_func=None, last_modified_func=None):
    5659    """
    5760    Decorator to support conditional retrieval (or change) for a view
Back to Top