Skip to content

Commit 64be595

Browse files
committed
use jinja2 i18n extension
enable autoescape for jinja2 templates
1 parent a63c1a4 commit 64be595

28 files changed

+270
-266
lines changed

roundup/cgi/engine_jinja2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class Jinja2Loader(LoaderBase):
4747
def __init__(self, dir):
4848
self._env = jinja2.Environment(
4949
loader=jinja2.FileSystemLoader(dir),
50-
extensions=[]
50+
extensions=['jinja2.ext.i18n'],
51+
autoescape=True
5152
)
5253

5354
# Adding a custom filter that can transform roundup's vars to unicode
@@ -87,7 +88,10 @@ def __init__(self, template):
8788
def render(self, client, classname, request, **options):
8889
# [ ] limit the information passed to the minimal necessary set
8990
c = context(client, self, classname, request)
90-
c.update({'options': options})
91+
92+
c.update({'options': options,
93+
'gettext': lambda s: s2u(client.gettext(s)),
94+
'ngettext': lambda s, p, n: s2u(client.ngettext(s, p, n))})
9195
s = self._tpl.render(c)
9296
return s if sys.version_info[0] > 2 else \
9397
s.encode(client.STORAGE_CHARSET, )
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
404 - {{ i18n.gettext('page not found')|u }}
4+
404 - {% trans %}page not found{% endtrans %}
55
{% endblock %}
66

77
{% block page_content %}
88
<div class='container-fluid'>
9-
<h1 class='text-error'>{{ i18n.gettext('404 - page not found')|u }}</h1>
10-
<p style='text-align: center'>{{ i18n.gettext('What were you looking for anyways?')|u }}</p>
9+
<h1 class='text-error'>{% trans %}404 - page not found{% endtrans %}</h1>
10+
<p style='text-align: center'>{% trans %}What were you looking for anyways?{% endtrans %}</p>
1111
</div>
1212
{% endblock %}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ i18n.gettext('Edit Collision')|u }} - {{ config.TRACKER_NAME }}
4+
{% trans %}Edit Collision{% endtrans %} - {{ config.TRACKER_NAME }}
55
{% endblock %}
66

77
{% block page_header %}
8-
{{ i18n.gettext('Edit Collision')|u }} - {{ config.TRACKER_NAME }}
8+
{% trans %}Edit Collision{% endtrans %} - {{ config.TRACKER_NAME }}
99
{% endblock %}
1010

1111
{% block content %}
1212
<p>
13-
{{ i18n.gettext('There has been a collision.
13+
{% trans %}There has been a collision.
1414
Another user updated this node
15-
while you were editing. Please') }}
16-
<a href='{{ context }}'>{{ i18n.gettext('reload')|u }}</a>
17-
{{ i18n.gettext('the node and review your edits.')|u }}
15+
while you were editing. Please{% endtrans %}
16+
<a href='{{ context }}'>{% trans %}reload{% endtrans %}</a>
17+
{% trans %}the node and review your edits.{% endtrans %}
1818
</p>
1919
{% endblock %}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ i18n.gettext('Empty page')|u }}
4+
{% trans %}Empty page{% endtrans %}
55
{% endblock %}
66

77
{% block page_content %}
88
<p>
9-
{{ i18n.gettext('Please specify your search parameters!')|u }}
9+
{% trans %}Please specify your search parameters!{% endtrans %}
1010
</p>
1111
{% endblock %}

share/roundup/templates/jinja2/html/_generic.index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ context._classname.capitalize() }} {{ i18n.gettext('editing')|u }}
4+
{{ context._classname.capitalize() }} {% trans %}editing{% endtrans %}
55
{% endblock %}
66

77
{% block page_header %}
8-
{{ context._classname.capitalize() }} {{ i18n.gettext('editing')|u }}
8+
{{ context._classname.capitalize() }} {% trans %}editing{% endtrans %}
99
{% endblock %}
1010

1111
{% block content %}
1212

1313
{% include 'layout/permission.html' %}
1414

1515
{% if context.is_view_ok() %}
16-
<p class="form-help">{{ i18n.gettext('
16+
<p class="form-help">{% trans %}
1717
You may edit the contents of the
1818
class using this form. Commas, newlines and double quotes (") must be
1919
handled delicately. You may include commas and newlines by enclosing the
2020
values in double-quotes ("). Double quotes themselves must be quoted by
2121
doubling ("").
22-
') }}</p>
22+
{% endtrans %}</p>
2323

24-
<p class="form-help">{{ i18n.gettext('
24+
<p class="form-help">{% trans %}
2525
Multilink properties have their multiple values colon (":") separated
2626
(... ,"one:two:three", ...)
27-
') }}</p>
27+
{% endtrans %}</p>
2828

29-
<p class="form-help">{{ i18n.gettext('
29+
<p class="form-help">{% trans %}
3030
Remove entries by deleting their line. Add new entries by appending
3131
them to the table - put an X in the id column. If you wish to restore a
3232
removed item and you know its id then just put that id in the id column.
33-
') }}</p>
33+
{% endtrans %}</p>
3434
<form method="POST" action='{{ context.designator() }}'>
35-
<textarea rows="15" style="width:90%" name="rows">{{ context.csv()|u|e }}</textarea>
35+
<textarea rows="15" style="width:90%" name="rows">{{ context.csv()|u }}</textarea>
3636
<br>
3737
<input name="@csrf" type="hidden" value="{{ utils.anti_csrf_nonce() }}">
3838
<input type="hidden" name="@action" value="editCSV">
39-
<input type="submit" value="{{ i18n.gettext('Edit Items')|u }}">
39+
<input type="submit" value="{% trans %}Edit Items{% endtrans %}">
4040
</form>
4141
{% endif %}
4242

share/roundup/templates/jinja2/html/file.index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
<h4>{{ i18n.gettext('Files')|u }}</h4>
1+
<h4>{% trans %}Files{% endtrans %}</h4>
22
<table class='table'>
33
<tr>
4-
<th>{{ i18n.gettext('File name')|u }}</th>
5-
<th>{{ i18n.gettext('Uploaded')|u }}</th>
6-
<th>{{ i18n.gettext('Type')|u }}</th>
7-
<th>{{ i18n.gettext('Edit')|u }}</th>
8-
<th>{{ i18n.gettext('Remove')|u }}</th>
4+
<th>{% trans %}File name{% endtrans %}</th>
5+
<th>{% trans %}Uploaded{% endtrans %}</th>
6+
<th>{% trans %}Type{% endtrans %}</th>
7+
<th>{% trans %}Edit{% endtrans %}</th>
8+
<th>{% trans %}Remove{% endtrans %}</th>
99
</tr>
1010
{% for file in context.files %}
1111
<tr>
1212
<td>
13-
<a href='{{ file.download_url() }}'>{{ file.name.plain()|u|e }}</a>
13+
<a href='{{ file.download_url() }}'>{{ file.name.plain()|u }}</a>
1414
</td>
15-
<td>{{ file.creator.plain()|u|e }}, {{ file.creation.plain()|u|e }}</td>
16-
<td>{{ file.type.plain()|u|e }}</td>
15+
<td>{{ file.creator.plain()|u }}, {{ file.creation.plain()|u }}</td>
16+
<td>{{ file.type.plain()|u }}</td>
1717
{% if file.is_edit_ok %}
1818
<td>
19-
<a href='file{{ file.id }}'>{{ i18n.gettext('edit')|u }}</a>
19+
<a href='file{{ file.id }}'>{% trans %}edit{% endtrans %}</a>
2020
</td>
2121
{% endif %}
2222
{% if context.is_edit_ok %}
@@ -25,7 +25,7 @@ <h4>{{ i18n.gettext('Files')|u }}</h4>
2525
<input type="hidden" name="@remove@files" value='{{ file.id }}'>
2626
<input name="@csrf" type="hidden" value="{{ utils.anti_csrf_nonce() }}">
2727
<input type="hidden" name="@action" value="edit">
28-
<input type="submit" value="{{ i18n.gettext('remove')|u }}">
28+
<input type="submit" value="{% trans %}remove{% endtrans %}">
2929
</form>
3030
</td>
3131
{% endif %}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ i18n.gettext('File display')|u }}
4+
{% trans %}File display{% endtrans %}
55
{% endblock %}
66

77
{% block page_header %}
8-
{{ i18n.gettext('File display')|u }}
8+
{% trans %}File display{% endtrans %}
99
{% endblock %}
1010

1111
{% block content %}
@@ -17,31 +17,31 @@
1717
enctype="multipart/form-data" action='{{ context.designator() }}'>
1818

1919
<dl class='dl-horizontal'>
20-
<dt>{{ i18n.gettext('Name')|u }}</dt>
21-
<dd>{{ context.name.field()|u }}</dd>
22-
<dt>{{ i18n.gettext('Content Type')|u }}</dt>
23-
<dd>{{ context.type.field()|u }}</dd>
20+
<dt>{% trans %}Name{% endtrans %}</dt>
21+
<dd>{{ context.name.field()|u|safe }}</dd>
22+
<dt>{% trans %}Content Type{% endtrans %}</dt>
23+
<dd>{{ context.type.field()|u|safe }}</dd>
2424
</dl>
2525

2626
<input type="hidden" name="@template" value="item">
2727
<input type="hidden" name="@required" value="name,type">
2828
{% if '@multilink' in request.form %}
2929
<input type="hidden" name="@multilink"
30-
value='{{ request.form["@multilink"].value()|u|e }}'>
30+
value='{{ request.form["@multilink"].value()|u }}'>
3131
{% endif %}
3232
<div class='form-actions'>
33-
{{ context.submit()|u }}
33+
{{ context.submit()|u|safe }}
3434
</div>
3535
</form>
3636
{% endif %}
3737

3838
{% if context.id and context.is_view_ok() %}
3939
<div class='row-fluid'>
40-
<a href='file{{ context.id }}/{{ context.name.plain()|u|e }}'>{{ i18n.gettext('Download')|u }}</a>
40+
<a href='file{{ context.id }}/{{ context.name.plain()|u }}'>{% trans %}Download{% endtrans %}</a>
4141
</div>
4242
{% endif %}
4343

4444
<div class='vspace-five'></div>
45-
{{ context.history()|u }}
45+
{{ context.history()|u|safe }}
4646

4747
{% endblock %}

share/roundup/templates/jinja2/html/home.classlist.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ i18n.gettext('List of classes')|u }}
4+
{% trans %}List of classes{% endtrans %}
55
{% endblock %}
66

77
{% block page_header %}
8-
{{ i18n.gettext('List of classes')|u }}
8+
{% trans %}List of classes{% endtrans %}
99
{% endblock %}
1010

1111
{% block content %}

share/roundup/templates/jinja2/html/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
filter=['status'],
55
columns=['id','activity','title','creator','assignedto', 'status'],
66
filterspec={'status':['-1','1','2','3','4','5','6','7']}
7-
)|u
7+
)|u|safe
88
}}

share/roundup/templates/jinja2/html/issue.index.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends 'layout/page.html' %}
22

33
{% block head_title %}
4-
{{ i18n.gettext('List of issues')|u }}
4+
{% trans %}List of issues{% endtrans %}
55
{% endblock %}
66

77
{% block page_header %}
8-
{{ i18n.gettext('List of issues')|u }}
8+
{% trans %}List of issues{% endtrans %}
99
{% endblock %}
1010

1111
{% block content %}
@@ -17,63 +17,63 @@
1717
<table class='table'>
1818
<tr class='info'>
1919
{% if request.show.priority %}
20-
<td>{{ i18n.gettext('Priority')|u }}</td>
20+
<td>{% trans %}Priority{% endtrans %}</td>
2121
{% endif %}
2222
{% if request.show.id %}
23-
<td>{{ i18n.gettext('ID')|u }}</td>
23+
<td>{% trans %}ID{% endtrans %}</td>
2424
{% endif %}
2525
{% if request.show.activity %}
26-
<td>{{ i18n.gettext('Activity')|u }}</td>
26+
<td>{% trans %}Activity{% endtrans %}</td>
2727
{% endif %}
2828
{% if request.show.actor %}
29-
<td>{{ i18n.gettext('Actor')|u }}</td>
29+
<td>{% trans %}Actor{% endtrans %}</td>
3030
{% endif %}
3131
{% if request.show.keyword %}
32-
<td>{{ i18n.gettext('Keyword')|u }}</td>
32+
<td>{% trans %}Keyword{% endtrans %}</td>
3333
{% endif %}
3434
{% if request.show.title %}
35-
<td>{{ i18n.gettext('Title')|u }}</td>
35+
<td>{% trans %}Title{% endtrans %}</td>
3636
{% endif %}
3737
{% if request.show.status %}
38-
<td>{{ i18n.gettext('Status')|u }}</td>
38+
<td>{% trans %}Status{% endtrans %}</td>
3939
{% endif %}
4040
{% if request.show.creator %}
41-
<td>{{ i18n.gettext('Creator')|u }}</td>
41+
<td>{% trans %}Creator{% endtrans %}</td>
4242
{% endif %}
4343
{% if request.show.assignedto %}
44-
<td>{{ i18n.gettext('Assigned To')|u }}</td>
44+
<td>{% trans %}Assigned To{% endtrans %}</td>
4545
{% endif %}
4646
</tr>
4747
{% for issue in request.batch() %}
4848
<tr>
4949
{% if request.show.priority %}
50-
<td>{{ issue.priority.plain()|u|e }}</td>
50+
<td>{{ issue.priority.plain()|u }}</td>
5151
{% endif %}
5252
{% if request.show.id %}
5353
<td>{{ issue.id }}</td>
5454
{% endif %}
5555
{% if request.show.activity %}
56-
<td>{{ issue.activity.reldate()|u|e }}</td>
56+
<td>{{ issue.activity.reldate()|u }}</td>
5757
{% endif %}
5858
{% if request.show.actor %}
59-
<td>{{ issue.actor.plain()|u|e }}</td>
59+
<td>{{ issue.actor.plain()|u }}</td>
6060
{% endif %}
6161
{% if request.show.keyword %}
62-
<td>{{ issue.keyword.plain()|u|e }}</td>
62+
<td>{{ issue.keyword.plain()|u }}</td>
6363
{% endif %}
6464
{% if request.show.title %}
6565
<td>
66-
<a href='issue{{ issue.id }}'>{{ issue.title.plain(hyperlink=0)|u|e }}</a>
66+
<a href='issue{{ issue.id }}'>{{ issue.title.plain(hyperlink=0)|u }}</a>
6767
</td>
6868
{% endif %}
6969
{% if request.show.status %}
70-
<td>{{ issue.status.plain()|u|e }}</td>
70+
<td>{{ issue.status.plain()|u }}</td>
7171
{% endif %}
7272
{% if request.show.creator %}
73-
<td>{{ issue.creator.plain()|u|e }}</td>
73+
<td>{{ issue.creator.plain()|u }}</td>
7474
{% endif %}
7575
{% if request.show.assignedto %}
76-
<td>{{ issue.assignedto.plain()|u|e }}</td>
76+
<td>{{ issue.assignedto.plain()|u }}</td>
7777
{% endif %}
7878
</tr>
7979
{% endfor %}
@@ -83,15 +83,15 @@
8383
<div class='pull-right'>
8484
<a class='btn btn-success'
8585
href="{{ request.indexargs_url('issue', {'@action':'export_csv'}) }}">
86-
{{ i18n.gettext('Download as CSV')|u }}
86+
{% trans %}Download as CSV{% endtrans %}
8787
</a>
8888
</div>
8989
</div>
9090

9191
{% include 'layout/sort.html' %}
9292

9393
{% else %}
94-
<p class='text-error'>{{ i18n.gettext('There are no issues yet!')|u }}</p>
94+
<p class='text-error'>{% trans %}There are no issues yet!{% endtrans %}</p>
9595
{% endif %}
9696

9797
{% endif %}

0 commit comments

Comments
 (0)