Decorators ====================================== Below is the list of decorators available in this project. .. _ajax_login_required: ajax_login_required -------------------------------------- This decorator works like the built-in Django `login_required `_ but it handles AJAX requests differently. For AJAX requests, this decorator passes back custom headers to tell the client to redirect to the login page. These headers are caught by a `ajaxComplete` listener contained within `jquery.dj.hilbert.js`. This is based on answers from the Stackoverflow question `"How to manage a redirect request after a JQuery Ajax call?" `_. .. code-block:: python @ajax_login_required def authenticated_view(request): return HttpResponse() .. _ajax_only: ajax_only -------------------------------------- The :ref:`ajax_only` decorator ensures that all requests made to a particular view are made as AJAX requests. Non-AJAX requests will recieve a 400 (Bad Request) response. This is based on `snippet 771 `_. .. code-block:: python @ajax_only def ajax_view(request): return HttpResponse() .. _anonymous_required: anonymous_required -------------------------------------- .. versionadded:: 0.2 This decorator is the opposite of `login_required `_ . It ensures that users attempting to view this page are not authenticated. By default this will redirect autheticated users to the server root '/' or you can specify another url as either an absolute path or as as named url pattern. .. code-block:: python @anonymous_required(url='/hilbert/test/simple/') def anonymous_only_view(request): return HttpResponse() .. _secure: secure -------------------------------------- .. versionadded:: 0.2 This decorator is similar to :ref:`SSLRedirectMiddleware` but works independently. Decorating a view with :ref:`secure` will force this view to be accessed only over SSL. .. code-block:: python @secure def secure_view(request): return HttpResponse()