cmlenz@438: .. -*- mode: rst; encoding: utf-8 -*- cmlenz@438: cmlenz@438: ============== cmlenz@438: Stream Filters cmlenz@438: ============== cmlenz@438: cmlenz@438: `Markup Streams`_ showed how to write filters and how they are applied to cmlenz@438: markup streams. This page describes the features of the various filters that cmlenz@438: come with Genshi itself. cmlenz@438: cmlenz@438: .. _`Markup Streams`: streams.html cmlenz@438: cmlenz@438: .. contents:: Contents cmlenz@438: :depth: 1 cmlenz@438: .. sectnum:: cmlenz@438: cmlenz@438: cmlenz@438: HTML Form Filler cmlenz@438: ================ cmlenz@438: cmlenz@438: The filter ``genshi.filters.HTMLFormFiller`` can automatically populate an HTML cmlenz@438: form from values provided as a simple dictionary. When using thi filter, you can cmlenz@438: basically omit any ``value``, ``selected``, or ``checked`` attributes from form cmlenz@438: controls in your templates, and let the filter do all that work for you. cmlenz@438: cmlenz@438: ``HTMLFormFiller`` takes a dictionary of data to populate the form with, where cmlenz@438: the keys should match the names of form elements, and the values determine the cmlenz@438: values of those controls. For example:: cmlenz@438: cmlenz@438: >>> from genshi.filters import HTMLFormFiller cmlenz@438: >>> from genshi.template import MarkupTemplate cmlenz@438: >>> template = MarkupTemplate("""
cmlenz@438: ...

cmlenz@438: ...
cmlenz@438: ...
cmlenz@438: ... cmlenz@438: ...

cmlenz@438: ...
""") cmlenz@438: >>> filler = HTMLFormFiller(data=dict(username='john', remember=True)) cmlenz@438: >>> print template.generate() | filler cmlenz@438:
cmlenz@438:

cmlenz@438:
cmlenz@438:
cmlenz@438: cmlenz@438:

cmlenz@438:
cmlenz@438: cmlenz@438: .. note:: This processing is done without in any way reparsing the template cmlenz@438: output. As any stream filter it operates after the template output is cmlenz@438: generated but *before* that output is actually serialized. cmlenz@438: cmlenz@438: The filter will of course also handle radio buttons as well as ``