[Grok-dev] Re: first thoughts on "regebro-guido-templates"

Martijn Faassen faassen at startifact.com
Tue Oct 30 12:44:37 EDT 2007


Hey,

On 10/30/07, Lennart Regebro <regebro at gmail.com> wrote:
> On 10/30/07, Martijn Faassen <faassen at startifact.com> wrote:
> > True, I hadn't considered that. What about introducing a new method
> > that does the combination, so that there's no requirement for the
> > person writing the plugin anywhere?
>
> So you mean something like this:
>
> class MyTemplate(object):
>
>     def namespace(self, view):
>         return {'request': view.request,
>                      'view': view}
>
>     def getNamespace(self, view):
>         return self.namespace(view).update(view.namespace())
>
>     def render(self, view):
>         return  self._template.render(**self.getNamespace(view))
>
> Where getNamespace would be the new method you talk about (and
> normally defined only on the baseclass)?

Excatly. This would keep both namespace() and render() without special
knowledge concerning dictionary construction. The only thing extra to
explain is that people typically shouldn't override getNamespace()
themselves (perhaps in a docstring in the interface).

Regards,

Martijn


More information about the Grok-dev mailing list