On Monday, March 14, 2022 at 11:06:58 AM UTC-7 [email protected] wrote:

> OK thanks Ryan.
>
> I'm facing some final problems with Genshi templates in Trac 1.4.3.
>
> It looks like Trac is trying to render my templates with Jinja2 instead of 
> Genshi...
>
> Is there anything I should do to force Genshi to render my templates?
>
> Here is the stack trace:
>
> 18:47:17 Trac[main] DEBUG: Rendering response with template 
> testmanagerstats.html
> 18:47:17 Trac[web_ui] DEBUG: TestManagerTemplateProvider init
> 18:47:17 Trac[wiki] DEBUG: WikiTestManagerInterface init
> 18:47:17 Trac[workflow] DEBUG: TestManagerWorkflowInterface init
> 18:47:17 Trac[chrome] ERROR: Jinja2 UndefinedError error while rendering 
> XML/HTML template 
> Traceback (most recent call last):
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/trac/web/chrome.py",
>  
> line 1706, in _iterable_jinja_content
>     for chunk in stream:
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/jinja2/environment.py",
>  
> line 1357, in __next__
>     return self._next()
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/jinja2/environment.py",
>  
> line 1334, in _buffered_generator
>     c = next(self._gen)
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/jinja2/environment.py",
>  
> line 1125, in generate
>     yield self.environment.handle_exception()
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/jinja2/environment.py",
>  
> line 832, in handle_exception
>     reraise(*rewrite_traceback_stack(source=source))
>   File 
> "/home/roberto/.cache/Python-Eggs/TestManager-1.10.3-py2.7.egg-tmp/testmanager/templates/testmanagerstats.html",
>  
> line 125, in top-level template code
>     <option value="${m['planid']}|${m['catpath']}">${m['name']}</option>
>   File 
> "/home/roberto/Documenti/build/pve-trac14-vero/lib/python2.7/site-packages/jinja2/environment.py",
>  
> line 452, in getitem
>     return obj[argument]
> UndefinedError: 'm' is undefined
>
>
> And the relevant template code, where it looks like the "py:for" directive 
> is not understood nor run:
>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";
> xmlns:xi="http://www.w3.org/2001/XInclude";
> xmlns:i18n="http://genshi.edgewall.org/i18n";
> xmlns:py="http://genshi.edgewall.org/";
> i18n:domain="testmanager"
> >
> <xi:include href="layout.html" />
> <xi:include href="macros.html" />
>
> # import 'macros.html' as jmacros with context
>
> [...]
> <select id="testplan" name="testplan">
> <option value="__all">All Test Plans</option>
> <py:for each="m in testplans">
> <option value="${m['planid']}|${m['catpath']}">${m['name']}</option>
> </py:for> 
> </select>
>
>
> And the code I use to render the template:
>
> class TestStatsPlugin(Component):
> implements(INavigationContributor, IRequestHandler, ITemplateProvider, 
> IPermissionRequestor)
>
> [...]
> def process_request(self, req):
> [...]
> return 'testmanagerstats.html', data
>
>
> Any help is appreciated. Thanks.
> Roberto
>

You'll need to return:

 return 'testmanagerstats.html', data, None

in order to tell Trac that the template being rendered is a Genshi 
template. Also, you can't use "import ... jmacros" in a Genshi template, 
that's Jinja2 syntax.

https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja#IRequestHandler

Ryan

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/trac-users/a7b670fa-a7be-453d-9c4b-f425df3a380bn%40googlegroups.com.

Reply via email to