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

cmlenz@500: ...
cmlenz@500: ...
cmlenz@500: ... cmlenz@500: ...

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

cmlenz@500:
cmlenz@500:
cmlenz@500: cmlenz@500:

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