[damned-lies] Use new Django 1.2 'if' capabilities in templates
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Use new Django 1.2 'if' capabilities in templates
- Date: Sat, 21 Aug 2010 10:11:42 +0000 (UTC)
commit a06c94eaba70d757321f00d1163c4d9ec9a3ae3f
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Aug 21 12:10:46 2010 +0200
Use new Django 1.2 'if' capabilities in templates
stats/templatetags/stats_extras.py | 27 -------------
templates/base.html | 46 +++++++++++-----------
templates/languages/language_release.html | 4 +-
templates/languages/language_release_stats.html | 12 +++---
templates/module_detail.html | 12 ++---
templates/people/person_detail.html | 4 +-
templates/release_detail.html | 8 ++--
templates/stats_show.html | 6 +--
templates/vertimus/vertimus_detail.html | 12 +++---
9 files changed, 50 insertions(+), 81 deletions(-)
---
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index 0a33bed..b8e55c6 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -26,30 +26,3 @@ def escapeat(value):
@register.filter
def domain_type(stat):
return stat.domain.get_type(stat.branch)
-
-class IfLessNode(template.Node):
- def __init__(self, val1, val2, nodelist_true, nodelist_false):
- self.val1 = val1
- self.val2 = val2
- self.nodelist_true = nodelist_true
- self.nodelist_false = nodelist_false
-
- def render(self, context):
- if self.val1.resolve(context) < self.val2.resolve(context):
- return self.nodelist_true.render(context)
- else:
- return self.nodelist_false.render(context)
-
- register tag
-def ifless(parser, token):
- bits = list(token.split_contents())
- if len(bits) != 3:
- raise template.TemplateSyntaxError, "%r takes two arguments" % bits[0]
- nodelist_true = parser.parse(('else', 'endifless'))
- token = parser.next_token()
- if token.contents == 'else':
- nodelist_false = parser.parse(('endifless',))
- parser.delete_first_token()
- else:
- nodelist_false = template.NodeList()
- return IfLessNode(parser.compile_filter(bits[1]), parser.compile_filter(bits[2]), nodelist_true, nodelist_false)
diff --git a/templates/base.html b/templates/base.html
index db6ee8c..278130a 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -36,31 +36,31 @@
<div id="tabs">
<ul id="portal-globalnav">
<li
-{% ifequal pageSection "home" %}
- class="selected"
-{% endifequal %}
+{% if pageSection == "home" %}
+ class="selected"
+{% endif %}
><a href="{% url home %}" title="{% trans "Back to Damned Lies home page" %}"><span>{% trans "Home" %}</span></a>
</li>
- <li
-{% ifequal pageSection "teams" %}
- class="selected"
-{% endifequal %}
- ><a href="{% url teams %}"><span>{% trans "Teams" %}</span></a></li>
- <li
-{% ifequal pageSection "languages" %}
- class="selected"
-{% endifequal %}
- ><a href="{% url languages %}"><span>{% trans "Languages" %}</span></a></li>
- <li
-{% ifequal pageSection "releases" %}
- class="selected"
-{% endifequal %}
- ><a href="{% url releases %}"><span>{% trans "Release sets" %}</span></a></li>
- <li
-{% ifequal pageSection "module" %}
- class="selected"
-{% endifequal %}
- ><a href="{% url modules %}"><span>{% trans "Modules" %}</span></a></li>
+ <li
+{% if pageSection == "teams" %}
+ class="selected"
+{% endif %}
+ ><a href="{% url teams %}"><span>{% trans "Teams" %}</span></a></li>
+ <li
+{% if pageSection == "languages" %}
+ class="selected"
+{% endif %}
+ ><a href="{% url languages %}"><span>{% trans "Languages" %}</span></a></li>
+ <li
+{% if pageSection == "releases" %}
+ class="selected"
+{% endif %}
+ ><a href="{% url releases %}"><span>{% trans "Release sets" %}</span></a></li>
+ <li
+{% if pageSection == "module" %}
+ class="selected"
+{% endif %}
+ ><a href="{% url modules %}"><span>{% trans "Modules" %}</span></a></li>
</ul>
</div> <!-- end of #tabs -->
</div> <!-- end of #header -->
diff --git a/templates/languages/language_release.html b/templates/languages/language_release.html
index ccea027..aa0aa33 100644
--- a/templates/languages/language_release.html
+++ b/templates/languages/language_release.html
@@ -29,9 +29,9 @@ $(document).ready(function()
<a href="#" onclick="return showHideCompleted();">{% trans "Show completed modules" %}</a>
</p>
-{% ifequal release.status "xternal" %}
+{% if release.status == "xternal" %}
<p><i>{% trans "The modules of this release are not part of the GNOME git repository. Please check each module's web page to see where to send translations." %}</i></p>
-{% endifequal %}
+{% endif %}
<h3>{{ stats_title }}</h3>
{% with stats as modstats %}
diff --git a/templates/languages/language_release_stats.html b/templates/languages/language_release_stats.html
index ac183ab..735c257 100644
--- a/templates/languages/language_release_stats.html
+++ b/templates/languages/language_release_stats.html
@@ -25,7 +25,7 @@
{# empty line to not disturb tablesorter if 1st line is a colspan #}
<tr style="display:none;"><td>mod</td><td>br</td><td>100</td><td></td><td>state</td><td></td></tr>
{% for catname,categ in modstats.categs.items %}
- {% ifnotequal catname "default" %}
+ {% if catname != "default" %}
<tr class="subheader"><td colspan="4" class="leftcell" style="font-weight: bold; padding-top:1em;">
{% with categ.cattransperc as percentage %}
{% with categ.catname as categname %}
@@ -33,7 +33,7 @@
{% endwith %}
{% endwith %}
</td><td></td></tr>
- {% endifnotequal %}
+ {% endif %}
{% for module in categ.modules %}
{% with module.0 as modname %}
@@ -42,11 +42,11 @@
{% with dom.0 as domname %}
{% with dom.1 as stat %}
{% if stat and not stat.is_fake %}
- {% ifequal stat.tr_percentage 100 %}
+ {% if stat.tr_percentage == 100 %}
<tr id="{{ modname }}-{{ stat.domain.id }}-complete">
{% else %}
<tr>
- {% endifequal %}
+ {% endif %}
<td class="leftcell">
{% if language %}
<a href="{% url vertimus_by_names modname,branch,stat.domain.name,language.locale %}">{{ stat.module_description }}
@@ -78,7 +78,7 @@
</td>
<td>
{% if stat.state.name %}
- {% ifnotequal stat.state.name "None" %}
+ {% if stat.state.name != "None" %}
<em><small>{{ stat.state.get_state }}</small></em></td>
<td><span style="display: none;">{{ stat.state.updated|date:"c" }}</span><em><small>{{ stat.state.updated|date:dateformat }}
{% else %}
@@ -86,7 +86,7 @@
<span class="comment">{{ stat.state.last_comment|truncatewords:12 }}</span>
{% endif %}
</td><td>
- {% endifnotequal %}
+ {% endif %}
{% else %} </td><td>
{% endif %}
</td>
diff --git a/templates/module_detail.html b/templates/module_detail.html
index 2b8bf27..adb4e38 100644
--- a/templates/module_detail.html
+++ b/templates/module_detail.html
@@ -1,6 +1,5 @@
{% extends "base.html" %}
{% load i18n %}
-{% load stats_extras %}
{% block title %}
{% blocktrans with module.get_description as name %}Module Statistics: {{ name }}{% endblocktrans %}
@@ -76,7 +75,7 @@ $(document).ready(function() {
<!-- Links to branches of module -->
<p><strong>{% trans "Branches:" %}</strong>
{% for branch in branches %}
- {% ifnotequal forloop.counter 1 %} - {% endifnotequal %}
+ {% if forloop.counter != 1 %} - {% endif %}
<a href="#{{ branch.name }}">{{ branch.name }}</a>
{% if branch.warnings %}
<img src="{{ MEDIA_URL }}img/warn.png" title="{{ branch.warnings }}" />
@@ -90,24 +89,23 @@ $(document).ready(function() {
<!-- Main loop through branches -->
{% for branch in branches %}
<h2><a href="." class="branch" id="{{ branch.name }}">
- {% ifless forloop.counter 3 %}
+ {% if forloop.counter < 3 %}
<img src="{{ MEDIA_URL }}img/open.png" /></a>
{% else %}
<img src="{{ MEDIA_URL }}img/closed.png" /></a>
- {% endifless %}
+ {% endif %}
<a name="{{ branch.name }}"></a>{{ branch.name }}
{% if branch.get_vcs_web_url %}
<small>(<a href="{{ branch.get_vcs_web_url }}">{% trans "Browse Repository" %}</a>)</small>
{% endif %}
</h2>
- {% ifless forloop.counter 3 %}
+ {% if forloop.counter < 3 %}
<div id="div-{{ branch.name }}" class="loaded">
{% include "branch_detail.html" %}
</div>
{% else %}
<div id="div-{{ branch.name }}" class="empty" style="display:none;"></div>
- {% endifless %}
-
+ {% endif %}
{% endfor %}
{% endif %}
diff --git a/templates/people/person_detail.html b/templates/people/person_detail.html
index 2fa5ad4..884a510 100644
--- a/templates/people/person_detail.html
+++ b/templates/people/person_detail.html
@@ -26,11 +26,11 @@ $(document).ready(function()
{% trans "Site Language:" %}
<select name="language">
{% for lang in LANGUAGES %}
- {% ifequal lang.0 LANGUAGE_CODE %}
+ {% if lang.0 == LANGUAGE_CODE %}
<option value="{{ lang.0 }}" selected="selected">{% trans lang.1 %}</option>
{% else %}
<option value="{{ lang.0 }}" >{% trans lang.1 %}</option>
- {% endifequal %}
+ {% endif %}
{% endfor %}
</select>
<br/>
diff --git a/templates/release_detail.html b/templates/release_detail.html
index a3622b1..41577c1 100644
--- a/templates/release_detail.html
+++ b/templates/release_detail.html
@@ -9,9 +9,9 @@
<h1>{% blocktrans with release.get_description as name %}{{ name }} Release{% endblocktrans %}</h1>
-{% ifequal release.status "external" %}
+{% if release.status == "external" %}
<p><i>{% trans "The modules of this release are not part of the GNOME Git repository. Please check each module's web page to see where to send translations." %}</i></p>
-{% endifequal %}
+{% endif %}
<table class="stats">
<thead>
@@ -42,13 +42,13 @@
</div>
</td>
- {% ifnotequal lstats.doc_trans|add:lstats.doc_fuzzy "0" %}
+ {% if lstats.doc_trans|add:lstats.doc_fuzzy != "0" %}
<td><a href="{% url language_release lstats.lang_locale release.name "doc" %}">
{{ lstats.doc_percent }}% ({{ lstats.doc_trans }}/{{ lstats.doc_fuzzy }}/{{ lstats.doc_untrans }})</a>
</td>
{% else %}
<td>-</td>
- {% endifnotequal %}
+ {% endif %}
<td style="width: 108px; text-align: center;">
<div class="graph">
diff --git a/templates/stats_show.html b/templates/stats_show.html
index a9c60a5..5688a54 100644
--- a/templates/stats_show.html
+++ b/templates/stats_show.html
@@ -6,12 +6,10 @@
{% if pot_stat|domain_type == "mallard" %}
<img src="{{ MEDIA_URL }}img/mallard.png" width="20" title="{% trans "This document is written in Mallard documentation format" %}" alt="mallard icon"/>
{% endif %}
- {% ifnotequal pot_stat.domain.directory 'help' %}
- {% ifnotequal pot_stat.domain.directory 'po' %}
+ {% if pot_stat.domain.directory != 'help' and pot_stat.domain.directory != 'po' %}
<br />
<span class="path">{{ pot_stat.domain.directory }}</span>
- {% endifnotequal %}
- {% endifnotequal %}
+ {% endif %}
</h3>
<a href="{{ pot_stat.po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a>
{{ pot_stat.pot_text }}
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 750d42c..4309e35 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -43,9 +43,9 @@ $(document).ready(function() {
<h2 class="plain">
{% trans "State:" %} {{ state.description }}
-{% ifnotequal state.name 'None' %}
+{% if state.name != 'None' %}
({{ state.updated|date:_("Y-m-d g:i a O") }})
-{% endifnotequal %}
+{% endif %}
</h2>
{% if module.get_comment %}
@@ -102,14 +102,14 @@ $(document).ready(function() {
{% if language.team.use_workflow %}
<div id="vertimus_actions_title">
<h2>
- {% ifequal level 0 %}
+ {% if level == 0 %}
{% trans "Actions" %}
{% else %}
{% blocktrans with level|ordinal|safe as human_level %}Archived Actions ({{ human_level }} archived series){% endblocktrans %}
<a href="{% url vertimus_by_names module.name,branch.name,domain.name,language.locale %}">
{% trans "(Return to current)" %}
</a>
- {% endifequal %}
+ {% endif %}
{% if grandparent_level %}
<a href="{% url vertimus_archives_by_names module.name,branch.name,domain.name,language.locale,grandparent_level %}">
{% trans "(Previous action history)" %}
@@ -168,7 +168,7 @@ $(document).ready(function() {
<p><em>{% trans "No current actions." %}</em></p>
{% endif %}
-{% ifequal level 0 %}
+{% if level == 0 %}
<h2>{% trans "New Action" %}</h2>
{% if action_form %}
@@ -186,7 +186,7 @@ $(document).ready(function() {
{% else %}
{% blocktrans with language.team.get_description as team_name %}You need to be authenticated and to be member of the {{ team_name }} team.{% endblocktrans %}
{% endif %}
-{% endifequal %}
+{% endif %}
{% else %}
<p><img src="{{ MEDIA_URL }}img/warn.png"/> {% trans "This team is not using the Vertimus translation workflow." %}</p>
{% endif %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]