close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 5 and Version 6 of RequestFilters


Ignore:
Timestamp:
Aug 22, 2008, 10:42:17 PM (16 years ago)
Author:
cmlenz
Comment:

Notes on @register_filter

Legend:

Unmodified
Added
Removed
Modified
  • RequestFilters

    v5 v6  
    55{{{
    66#!python
     7from diva.core import register_filter
     8
     9@register_filter('mine', requires='error-handling')
    710def my_filter(request, response, chain):
    811    # Here you do anything you need to do before the request handler kicks in
     
    1821A request filter can of course also manipulate the return value of the handler. For example, if the return value is a Genshi markup stream, it could apply stream filters.
    1922
     23The `@register_filter` decorator is used to determine the order in which filters are applied. The first argument defines the abstract service provided by the filter, while dependencies on other filters are specified with the `requires` argument.
     24
    2025== Default Request Filters ==
    2126
    2227The following request filters are active by default unless you remove them:
    2328
    24  `diva.errors.error_filter`:: Intercepts exceptions and displays either a friendly error page or the debugging page
    25  `diva.templating.template_filter`:: Serializes Genshi template output streams
    26  `diva.i18n.l10n_filter`:: Handles locale negotiation and makes the corresponding translations catalog available
    27  `diva.http.caching_filter`:: Adds default cache control headers to responses
    28  `diva.forms.form_filter`:: Automatically populates HTML forms from previously entered data, and provides optional CSRF protection
     29 `diva.errors.error_filter` (“error-handling”):: Intercepts exceptions and displays either a friendly error page or the debugging page
     30 `diva.templating.template_filter` (“templating”):: Serializes Genshi template output streams
     31 `diva.i18n.l10n_filter` (“localization”):: Handles locale negotiation and makes the corresponding translations catalog available
     32 `diva.http.caching_filter` (“caching”):: Adds default cache control headers to responses
     33 `diva.forms.form_filter` (“form-processing”):: Automatically populates HTML forms from previously entered data, and provides optional CSRF protection
     34
     35In addition, the following request filters are available but not enabled by default:
     36
     37 `diva.auth.authn_filter` (“authentication”):: Performs HTTP or cookie-based [AuthFramework authentication]
    2938
    3039== Setting up Request Filters ==
     
    5160This implementation removes a number of the default filters. You could also add any custom filters you may have, etc.
    5261
    53 Note that the ordering of request filters is quite important. For example, if you insert your custom filter before the `error_filter`, an exception raised in your filter function will not result in a friendly error page, but rather result in the exception being propagated all the way up to the WSGI gateway. If you insert your filter before the `template_filter`, you will not get a Genshi stream as return value of the next function in the chain, but rather the rendered text.
    54 
    55 When in doubt, add custom filters close to the end of the list.
    56 
    5762== When to Use Request Filters ==
    5863