File tree Expand file tree Collapse file tree 4 files changed +18
-3
lines changed
share/roundup/templates/jinja2/html Expand file tree Collapse file tree 4 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,10 @@ Fixed:
173173- Help-Window now gets focus, this prevents the case that help doesn't
174174 work because an old help-window is below the main window.
175175 (Ralf Schlatterbeck)
176+ - issue2550811 20% fix: jinja2 template engine now has an example
177+ how to use non-ascii unicode contents with a custom filter ('|u').
178+ See updates on http://www.roundup-tracker.org/cgi-bin/moin.cgi/Jinja2
179+ (Bernhard Reiter)
176180
177181
1781822013-07-06: 1.5.0
Original file line number Diff line number Diff line change 3434import jinja2
3535import gettext
3636
37+ from types import MethodType
38+
3739# http://jinja.pocoo.org/docs/api/#loaders
3840
3941from roundup .cgi .templating import context , LoaderBase , TemplateBase
@@ -43,13 +45,22 @@ def __init__(self, dir):
4345 extensions = [
4446 'jinja2.ext.autoescape' ,
4547 ]
46- print "Jinja2 templates: " , dir
48+ print "Jinja2 templates: " , dir
4749 print "Extensions: " , extensions
4850 self ._env = jinja2 .Environment (
4951 loader = jinja2 .FileSystemLoader (dir ),
5052 extensions = extensions
5153 )
5254
55+ # Adding a custom filter that can transform roundup's vars to unicode
56+ # This is necessary because jinja2 can only deal with unicode objects
57+ # and roundup uses utf-8 for the internal representation.
58+ # The automatic conversion will assume 'ascii' and fail sometime.
59+ # Analysed with roundup 1.5.0 and jinja 2.7.1. See issue2550811.
60+ self ._env .filters ["u" ] = lambda s : \
61+ unicode (s (), "utf-8" ) if type (s ) == MethodType \
62+ else unicode (s , "utf-8" )
63+
5364 def check (self , tplname ):
5465 #print tplname
5566 try :
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ <h4>Messages</h4>
6464 </ div >
6565 </ div >
6666 < div class ='row-fluid '>
67- < pre > {{ msg.content.hyperlinked() }}</ pre >
67+ < pre > {{ msg.content.hyperlinked()|u }}</ pre >
6868 </ div >
6969 {% endfor %}
7070 {% endif %}
Original file line number Diff line number Diff line change 3636
3737 < div class ='row-fluid '>
3838 < h4 > Content</ h4 >
39- < pre > {{ context.content.hyperlinked }}</ pre >
39+ < pre > {{ context.content.hyperlinked|u }}</ pre >
4040 </ div >
4141 {% endif %}
4242
You can’t perform that action at this time.
0 commit comments