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.
- Timestamp:
-
Aug 22, 2008, 10:42:17 PM (16 years ago)
- Author:
-
cmlenz
- Comment:
-
Notes on @register_filter
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v5
|
v6
|
|
5 | 5 | {{{ |
6 | 6 | #!python |
| 7 | from diva.core import register_filter |
| 8 | |
| 9 | @register_filter('mine', requires='error-handling') |
7 | 10 | def my_filter(request, response, chain): |
8 | 11 | # Here you do anything you need to do before the request handler kicks in |
… |
… |
|
18 | 21 | A 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. |
19 | 22 | |
| 23 | The `@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 | |
20 | 25 | == Default Request Filters == |
21 | 26 | |
22 | 27 | The following request filters are active by default unless you remove them: |
23 | 28 | |
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 | |
| 35 | In 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] |
29 | 38 | |
30 | 39 | == Setting up Request Filters == |
… |
… |
|
51 | 60 | This implementation removes a number of the default filters. You could also add any custom filters you may have, etc. |
52 | 61 | |
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 | | |
57 | 62 | == When to Use Request Filters == |
58 | 63 | |