Opened 16 years ago
Closed 16 years ago
#273 closed defect (wontfix)
HTMLFormFiller has wrong __call__ signature for use by Template.generate()
Reported by: | mitch@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Template processing | Version: | 0.5.1 |
Keywords: | Cc: |
Description
HTMLFormFiller's __call__ signature is:
def __call__(self, stream):
Template.generate() calls filters via:
for filter_ in self.filters: stream = filter_(iter(stream), ctxt, **vars)
This causes an error if you try to insert a filter into a template's list of filters in a "template_loaded" callback function:
def template_loaded(template): filler = HTMLFormFiller(data=dict(name='Joe', remember=True)) template.filters.insert(0, filler)
A simple workaround is to wrap HTMLFormFiller:
class FormFiller(object): def __init__(self, *args, **kwargs): self.filler = HTMLFormFiller(*args, **kwargs) def __call__(self, stream, ctxt): return self.filler(stream)
Then:
def template_loaded(template): filler = FormFiller(data=dict(name='Joe', remember=True)) template.filters.insert(0, filler)
Change History (1)
comment:1 Changed 16 years ago by cmlenz
- Milestone 0.5.2 deleted
- Resolution set to wontfix
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.
I don't think it makes sense to use the HTMLFormFiller as a template filter this way, as the data dictionary changes all the time, likely for every render. Note that template filters are only set up the first time the template is instantiated, so using your code, you'll be getting the same form data for every render.
Instead of registering it as a template filter, the intended use is as an output stream filter: