Edgewall Software

Ticket #273 (closed defect: wontfix)

Opened 3 years ago

Last modified 3 years ago

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)

Attachments

Change History

Changed 3 years ago by cmlenz

  • status changed from new to closed
  • resolution set to wontfix
  • milestone 0.5.2 deleted

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:

  stream = tmpl.generate(**data) | HTMLFormFiller(data={'foo': 'bar'})
  print stream.render('html')

Add/Change #273 (HTMLFormFiller has wrong __call__ signature for use by Template.generate())

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.