Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 4923768585584640: Issue 2179 - [cms] Give Jinja2 templates a way to set global parameters (Closed)

Created:
March 19, 2015, 9:28 p.m. by Wladimir Palant
Modified:
March 20, 2015, 4:23 p.m.
Reviewers:
Sebastian Noack
Visibility:
Public.

Description

Issue 2179 - [cms] Give Jinja2 templates a way to set global parameters

Patch Set 1 : #

Total comments: 3

Patch Set 2 : Extract template variables automatically #

Unified diffs Side-by-side diffs Delta from patch set Stats (+5 lines, -1 line) Patch
M cms/converters.py View 1 1 chunk +5 lines, -1 line 0 comments Download

Messages

Total messages: 4
Wladimir Palant
March 19, 2015, 9:28 p.m. (2015-03-19 21:28:45 UTC) #1
Sebastian Noack
http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/converters.py File cms/converters.py (right): http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/converters.py#newcode297 cms/converters.py:297: return template.render(self._params, params=self._params) Note that modifying the params dict ...
March 20, 2015, 9:44 a.m. (2015-03-20 09:44:35 UTC) #2
Wladimir Palant
http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/converters.py File cms/converters.py (right): http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/converters.py#newcode297 cms/converters.py:297: return template.render(self._params, params=self._params) On 2015/03/20 09:44:36, Sebastian Noack wrote: ...
March 20, 2015, 3:31 p.m. (2015-03-20 15:31:39 UTC) #3
Sebastian Noack
March 20, 2015, 3:53 p.m. (2015-03-20 15:53:18 UTC) #4
LGTM. Don't forget to update the issue description as well.

http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/...
File cms/converters.py (right):

http://codereview.adblockplus.org/4923768585584640/diff/5741031244955648/cms/...
cms/converters.py:297: return template.render(self._params, params=self._params)
On 2015/03/20 15:31:39, Wladimir Palant wrote:
> On 2015/03/20 09:44:36, Sebastian Noack wrote:
> > So how about:
> > 
> >   module = template.make_module(self._params)
> >   for key, value in module.__dict__.iteritems():
> >     if not key.startswith("_"):
> >       self._params[key] = value
> >   return unicode(module)
> > 
> > That way you can just keep using the regular {% set %} statement to set
> > variables. And variables set in the template will be copied to the
> self._params.
> 
> The complication here: only variables set at top level will work. So setting
> conditionally for example is extremely awkward. But - fine with me, I managed
to
> get it working.
> 
> I'm somewhat concerned about dumping every exported variable into self._params
> but I don't see a better solution right now.

I think it's the best we can realistically do.

Powered by Google App Engine
This is Rietveld