[extensions-web/jingo] Start a port to Jinja/Jingo
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/jingo] Start a port to Jinja/Jingo
- Date: Fri, 25 Nov 2011 01:32:35 +0000 (UTC)
commit fb80962f536a6256edc44f4ea2f49487b2809a17
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Nov 23 20:28:15 2011 -0500
Start a port to Jinja/Jingo
This will help us for i18n in the long run
sweettooth/auth/templates/registration/login.html | 14 +++---
.../templates/registration/login_popup_form.html | 8 ++--
.../registration/password_change_form.html | 4 +-
.../registration/password_reset_confirm.html | 4 +-
.../registration/password_reset_form.html | 4 +-
.../auth/templates/registration/profile.html | 16 +++----
.../templates/registration/registration_form.html | 4 +-
.../auth/templates/registration/settings.html | 2 +-
.../templates/errorreports/report.html | 8 ++--
sweettooth/extensions/helpers.py | 44 ++++++++++++++++++++
.../extensions/templates/extensions/comments.html | 24 ++++------
.../extensions/templates/extensions/detail.html | 25 +++++------
.../templates/extensions/detail_edit.html | 21 +++++----
.../extensions/templates/extensions/list.html | 11 ++---
.../extensions/templates/extensions/upload.html | 2 +-
sweettooth/extensions/templatetags/gravatar.py | 2 -
sweettooth/extensions/templatetags/paginator.py | 4 +-
sweettooth/ratings/forms.py | 5 +-
sweettooth/ratings/helpers.py | 32 ++++++++++++++
sweettooth/review/templates/review/list.html | 8 ++--
sweettooth/review/templates/review/review.html | 25 +++++------
.../review/templates/review/review_reviewer.html | 6 +-
sweettooth/settings.py | 6 +++
sweettooth/templates/base.html | 30 ++++++--------
24 files changed, 188 insertions(+), 121 deletions(-)
---
diff --git a/sweettooth/auth/templates/registration/login.html b/sweettooth/auth/templates/registration/login.html
index a61f1ee..a1c9b89 100644
--- a/sweettooth/auth/templates/registration/login.html
+++ b/sweettooth/auth/templates/registration/login.html
@@ -2,23 +2,23 @@
{% block body %}
<form action="" method="POST" id="auth_form">
<input type="hidden" name="next" value="{{ next }}">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<ol>
<li>
{% for error in form.username.errors %}
<p class="error">{{ error }}</p>
{% endfor %}
- {{ form.username.label_tag }}
- {{ form.username }}
+ {{ form.username.label_tag()|safe }}
+ {{ form.username|safe }}
</li>
<li>
{% for error in form.password.errors %}
<p class="error">{{ error }}</p>
{% endfor %}
- {{ form.password.label_tag }}
- {{ form.password }}
+ {{ form.password.label_tag()|safe }}
+ {{ form.password|safe }}
</li>
<li class="submit">
@@ -27,6 +27,6 @@
</ol>
</form>
-<a href="{% url registration_register %}">Register</a>
-<a href="{% url auth_password_reset %}">Forgot your password?</a>
+<a href="{{ url('registration_register') }}">Register</a>
+<a href="{{ url('auth_password_reset') }}">Forgot your password?</a>
{% endblock %}
diff --git a/sweettooth/auth/templates/registration/login_popup_form.html b/sweettooth/auth/templates/registration/login_popup_form.html
index dcd49e0..1ecb207 100644
--- a/sweettooth/auth/templates/registration/login_popup_form.html
+++ b/sweettooth/auth/templates/registration/login_popup_form.html
@@ -1,6 +1,6 @@
-<form action="{% url auth-login %}" method="POST" class="login_popup_form">
- {% csrf_token %}
- {{ login_popup_form.as_plain }}
+<form action="{{ url('auth-login') }}" method="POST" class="login_popup_form">
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
+ {{ login_popup_form.as_plain()|safe }}
<input type="submit" value="Login">
- <a href="{% url registration_register %}">Register</a>
+ <a href="{{ url('registration_register') }}">Register</a>
</form>
diff --git a/sweettooth/auth/templates/registration/password_change_form.html b/sweettooth/auth/templates/registration/password_change_form.html
index bb7aad4..24e0ceb 100644
--- a/sweettooth/auth/templates/registration/password_change_form.html
+++ b/sweettooth/auth/templates/registration/password_change_form.html
@@ -2,9 +2,9 @@
{% block body %}
<h3>Change your password</h3>
<form action="" method="POST">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<ol>
- {{ form.as_ul }}
+ {{ form.as_ul()|safe }}
<li class="submit">
<input type="submit" value="Change password">
diff --git a/sweettooth/auth/templates/registration/password_reset_confirm.html b/sweettooth/auth/templates/registration/password_reset_confirm.html
index 86ef87c..1d13c1a 100644
--- a/sweettooth/auth/templates/registration/password_reset_confirm.html
+++ b/sweettooth/auth/templates/registration/password_reset_confirm.html
@@ -3,9 +3,9 @@
{% if validlink %}
<h3> Password reset </h3>
<form action="" method="POST">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<ol>
- {{ form.as_ul }}
+ {{ form.as_ul()|safe }}
<li class="submit">
<input type="submit" value="Reset your password">
diff --git a/sweettooth/auth/templates/registration/password_reset_form.html b/sweettooth/auth/templates/registration/password_reset_form.html
index 8c2921c..02db5f7 100644
--- a/sweettooth/auth/templates/registration/password_reset_form.html
+++ b/sweettooth/auth/templates/registration/password_reset_form.html
@@ -2,9 +2,9 @@
{% block body %}
<h3> Password reset </h3>
<form action="" method="POST">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<ol>
- {{ form.as_ul }}
+ {{ form.as_ul()|safe }}
<li class="submit">
<input type="submit" value="Reset your password">
diff --git a/sweettooth/auth/templates/registration/profile.html b/sweettooth/auth/templates/registration/profile.html
index beb9ad0..6f1f854 100644
--- a/sweettooth/auth/templates/registration/profile.html
+++ b/sweettooth/auth/templates/registration/profile.html
@@ -1,24 +1,22 @@
{% extends "base.html" %}
-{% block title %}{{ display_name }}'s Profile - {{ block.super }}{% endblock %}
+{% block title %}{{ display_name }}'s Profile - {{ super() }}{% endblock %}
{% block body %}
-{% load thumbnail %}
-{% load gravatar %}
<div class="profile">
{% if is_editable %}
<h2 class="editable"
id="new_display_name"
- editurl="{% url auth-ajax-edit-display-name %}">{{ display_name }}</h2>
+ editurl="{{ url('auth-ajax-edit-display-name') }}">{{ display_name }}</h2>
{% else %}
<h2>{{ display_name }}</h2>
{% endif %}
- <img class="gravatar" src="{% gravatar_url user.email 128 %}">
+ <img class="gravatar" src="{{ gravatar_url('user.email', 128) }}">
<h3> {{ display_name }} has authored </h3>
<ul>
{% for extension in extensions %}
<li class="extension profile">
- <h4 class="extension-name"><a href="{% url extensions-detail pk=extension.pk %}"> <img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h4>
+ <h4 class="extension-name"><a href="{{ url('extensions-detail', pk=extension.pk) }}"> <img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h4>
<p class="description">
{{ extension.description }}
</p>
@@ -30,14 +28,14 @@
<div class="reviews">
{% for review in reviews %}
<div class="review">
- <a href="{% url extensions-version-detail ext_pk=review.version.extension.pk slug=review.version.extension.slug pk=review.version.pk %}">
+ <a href="{{ url('extensions-version-detail', ext_pk=review.version.extension.pk, slug=review.version.extension.slug, pk=review.version.pk) }}">
<span class="extension-name">{{ review.version.extension.name }}</span>
<span class="extension-version">(version {{ review.version.version }})</span>
</a>
- <abbr class="timestamp" title="{{ review.date|date:"c" }}">{{ review.date|date:"F j, Y" }}</abbr>
+ <abbr class="timestamp" title="{{ review.date.isoformat() }}">{{ review.date|datetime("%B %d, %Y") }}</abbr>
<blockquote>{{ review.comments }}</blockquote>
</div>
- {% empty %}
+ {% else %}
<p>No reviews.</p>
{% endfor %}
</div>
diff --git a/sweettooth/auth/templates/registration/registration_form.html b/sweettooth/auth/templates/registration/registration_form.html
index a074183..7a74161 100644
--- a/sweettooth/auth/templates/registration/registration_form.html
+++ b/sweettooth/auth/templates/registration/registration_form.html
@@ -1,9 +1,9 @@
{% extends "base.html" %}
{% block body %}
<form action="" method="POST" id="auth_form">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<ol>
- {{ form.as_ul }}
+ {{ form.as_ul()|safe }}
<li class="submit">
<input type="submit" value="Register">
diff --git a/sweettooth/auth/templates/registration/settings.html b/sweettooth/auth/templates/registration/settings.html
index b64f7fb..1bcc2c6 100644
--- a/sweettooth/auth/templates/registration/settings.html
+++ b/sweettooth/auth/templates/registration/settings.html
@@ -2,6 +2,6 @@
{% block body %}
<h3> Settings </h3>
<ul>
- <li> <a href="{% url auth_password_change %}">Change your password</a> </li>
+ <li> <a href="{{ url('auth_password_change') }}">Change your password</a> </li>
</ul>
{% endblock %}
diff --git a/sweettooth/errorreports/templates/errorreports/report.html b/sweettooth/errorreports/templates/errorreports/report.html
index 24ea2a2..4544c31 100644
--- a/sweettooth/errorreports/templates/errorreports/report.html
+++ b/sweettooth/errorreports/templates/errorreports/report.html
@@ -1,18 +1,18 @@
{% extends "base.html" %}
-{% block title %}Report Error for "{{ extension.name }}" - {{ block.super }}{% endblock %}
+{% block title %}Report Error for "{{ extension.name }}" - {{ super() }}{% endblock %}
{% block body %}
<h2><em>{{ extension.name }}</em> is malfunctioning?</h2>
<p>Please look through the information below and edit out any unwanted information.</p>
<form action="" method="POST" id="error_report" data-uuid="{{ extension.uuid }}">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<h3> Comments for the author </h3>
- {{ form.comments }}
+ {{ form.comments|safe }}
<p>GNOME Shell Extensions will not provide the extension author with any contact information by default. If you wish to be contacted by the extension author, please check the box below.</p>
- {{ form.can_contact }} {{ form.can_contact.label_tag }}
+ {{ form.can_contact|safe }} {{ form.can_contact.label_tag()|safe }}
<input type="submit" value="Report Errors">
</form>
diff --git a/sweettooth/extensions/helpers.py b/sweettooth/extensions/helpers.py
new file mode 100644
index 0000000..373dd02
--- /dev/null
+++ b/sweettooth/extensions/helpers.py
@@ -0,0 +1,44 @@
+
+import hashlib
+import urllib
+
+from jingo import register
+from jinja2.utils import Markup
+
+from sorl.thumbnail.shortcuts import get_thumbnail
+
+GRAVATAR_BASE = "https://secure.gravatar.com/avatar/%s?%s"
+
+ register function
+def paginator_html(page_obj, context=3):
+ number = page_obj.number
+ context_left = range(max(number-context, 2), number)
+ context_right = range(number+1, min(number+context+1, page_obj.paginator.num_pages+1))
+
+ lines = []
+
+ if page_obj.has_previous():
+ lines.append(u'<a class="number first" href="?page=1">1</a>')
+ if number-context > 2:
+ lines.append(u'<span class="ellipses">...</span>')
+
+ for i in context_left:
+ lines.append(u'<a class="prev number" href="?page=%d">%d</a>' % (i, i))
+
+ lines.append(u'<span class="current number">%d</span>' % (number,))
+
+ if page_obj.has_next():
+ for i in context_right:
+ lines.append(u'<a class="next number" href="?page=%d">%d</a>' % (i, i))
+
+ return Markup(u'\n'.join(lines))
+
+ register function
+def gravatar_url(email, size=70, default="http://planet.gnome.org/heads/nobody.png"):
+ email_md5 = hashlib.md5(email.lower()).hexdigest()
+ options = urllib.urlencode(dict(d=default, s=size))
+ return GRAVATAR_BASE % (email_md5, options)
+
+ register function
+def thumbnail(field, geometry):
+ return get_thumbnail(field, geometry)
diff --git a/sweettooth/extensions/templates/extensions/comments.html b/sweettooth/extensions/templates/extensions/comments.html
index 3612e8e..91d70d9 100644
--- a/sweettooth/extensions/templates/extensions/comments.html
+++ b/sweettooth/extensions/templates/extensions/comments.html
@@ -1,37 +1,33 @@
<div id="comments">
<h4>User comments</h4>
- {% load comments %}
- {% load gravatar %}
- {% load rating %}
- {% get_comment_list for extension as comments %}
- {% for comment in comments %}
+ {% for comment in get_comments(extension) %}
<div class="comment">
- <img src="{% gravatar_url comment.user_email %}" class="gravatar">
+ <img src="{{ gravatar_url(comment.user_email) }}" class="gravatar">
<div class="rating-author">
<div class="rating">
- {% rating comment.rating 5 %}
+ {{ rating(comment.rating, 5) }}
</div> by
- <a class="comment-author" href="{% url auth-profile user=comment.user.username %}">{{ comment.user }}</a>
+ <a class="comment-author" href="{{ url('auth-profile', user=comment.user.username) }}">{{ comment.user }}</a>
</div>
<p>{{ comment.comment }}</p>
- <abbr class="timestamp" title="{{ comment.submit_date|date:"c" }}">{{ comment.submit_date|date:"F j, Y" }}</abbr>
+ <abbr class="timestamp" title="{{ comment.submit_date.isoformat() }}">{{ comment.submit_date|datetime("%B %d, %Y") }}</abbr>
</div>
<hr>
- {% empty %}
+ {% else %}
There are no comments.
{% endfor %}
</div>
<div id="new-comment-form">
<div>
<h4>Your opinion</h4>
- {% if request.user.is_authenticated %}
+ {% if request.user.is_authenticated() %}
<div class="report rating">
<span class="txt">It worked, and...</span>
- {% render_comment_form for extension %}
+ {{ render_comment_form(extension) }}
</div>
<div class="report error">
- <a class="txt" href="{% url errorreports-report pk=extension.pk %}" class="report error">Help! It didn't work!</a>
+ <a class="txt" href="{{ url('errorreports-report', pk=extension.pk) }}" class="report error">Help! It didn't work!</a>
<p>
Errors should be reported through the error reporting tool — it
helps extension authors be known about bugs in their extension!
@@ -39,7 +35,7 @@
</div>
{% else %}
<p class="unauthenticated">
- Unfortunately, to help prevent spam, we require that you <a href="{% url auth-login %}">log in to GNOME Shell Extensions</a> in order to post a comment or report an error. You understand, right?
+ Unfortunately, to help prevent spam, we require that you <a href="{{ url('auth-login') }}">log in to GNOME Shell Extensions</a> in order to post a comment or report an error. You understand, right?
</p>
{% endif %}
</div>
diff --git a/sweettooth/extensions/templates/extensions/detail.html b/sweettooth/extensions/templates/extensions/detail.html
index 4f5fb08..6c2d143 100644
--- a/sweettooth/extensions/templates/extensions/detail.html
+++ b/sweettooth/extensions/templates/extensions/detail.html
@@ -1,25 +1,22 @@
{% extends "base.html" %}
-{% load thumbnail %}
-{% block title %}{{ extension.name }} - {{ block.super }}{% endblock %}
+{% block title %}{{ extension.name }} - {{ super() }}{% endblock %}
-{% block extra-messages %}
- {{ block.super }}
+{% block extra_messages %}
+ {{ super() }}
{% if is_rejected %}
- {% spaceless %}
<p class="message error">
This version of {{ extension.name }} was rejected.
- <a href="{% url extensions-detail pk=extension.pk %}">View the latest accepted version.</a>
+ <a href="{{ url('extensions-detail', pk=extension.pk) }}">View the latest accepted version.</a>
</p>
- {% endspaceless %}
{% else %} {% if old_version %}
<p class="message warning">
- You are viewing an old version of <a href="{% url extensions-detail pk=extension.pk %}">{{ extension.name }}</a>
+ You are viewing an old version of <a href="{{ url('extensions-detail', pk=extension.pk) }}">{{ extension.name }}</a>
</p>
{% endif %} {% endif %}
{% endblock %}
{% block body %}
-{% block extra-body-header %}
+{% block extra_body_header %}
{% endblock %}
<div class="extension"
@@ -33,18 +30,18 @@
{% endblock icon %}
{% if extension.screenshot %}
- {% thumbnail extension.screenshot "300x200" as th %}
{% block screenshot %}
- <a href="{{ extension.screenshot.url }}" class="screenshot"><img src="{{ th.url }}" /></a>
+ <a href="{{ extension.screenshot.url }}" class="screenshot">
+ <img src="{{ thumbnail(extension.screenshot, '300x200').url }}" />
+ </a>
{% endblock screenshot %}
- {% endthumbnail %}
{% else %}
- {% block no-screenshot %}
+ {% block no_screenshot %}
{% endblock %}
{% endif %}
<h3 class="extension-name" id="extension_name">{{ extension.name }}</h3>
- <span class="author">by <a href="{% url auth-profile user=extension.creator.username %}">{{ extension.creator }}</a></span>
+ <span class="author">by <a href="{{ url('auth-profile', user=extension.creator.username) }}">{{ extension.creator }}</a></span>
<p class="description" id="extension_description">
{{ extension.description }}
</p>
diff --git a/sweettooth/extensions/templates/extensions/detail_edit.html b/sweettooth/extensions/templates/extensions/detail_edit.html
index b6ee5f8..fdb4fb6 100644
--- a/sweettooth/extensions/templates/extensions/detail_edit.html
+++ b/sweettooth/extensions/templates/extensions/detail_edit.html
@@ -1,7 +1,7 @@
{% extends "extensions/detail.html" %}
-{% block extra-body-header %}
- {{ block.super }}
+{% block extra_body_header %}
+ {{ super() }}
{% if is_preview %}
<div class="step edit">
<h2 class="steptitle">Step <span>2</span></h2>
@@ -35,7 +35,7 @@
A reviewer will review the extension you submitted to make sure there's nothing too
dangerous. You'll be emailed the result of the review.
- <button id="submit-ajax" data-url="{% url extensions-ajax-submit pk=version.pk %}">
+ <button id="submit-ajax" data-url="{{ url('extensions-ajax-submit', pk=version.pk) }}">
Submit the extension for review.
</button>
</p>
@@ -43,18 +43,18 @@
{% endif %}
{% if not is_preview %}
- <a href="{% url extensions-upload-file pk=extension.pk %}">Upload a new version</a>
+ <a href="{{ url('extensions-upload-file', pk=extension.pk) }}">Upload a new version</a>
{% endif %}
{% endblock %}
{% block screenshot %}
<div class="screenshot upload">
- <img src="{{ th.url }}" />
+ <img src="{{ thumbnail(extension.screenshot, '300x200').url }}" />
<input type="file" accept="image/*">
</div>
{% endblock %}
-{% block no-screenshot %}
+{% block no_screenshot %}
<div class="screenshot upload placeholder">
<div class="text">
<span>Upload a screenshot</span>
@@ -71,10 +71,11 @@
</div>
{% endblock %}
-{% block document-ready %}{{ block.super }}
- $("#extension_name, #extension_description, #extension_url").csrfEditable("{% url extensions-ajax-inline pk=extension.pk %}");
+{% block document_ready %}{{ super() }}
+ $("h3, p.description").csrfEditable("{{ url('extensions-ajax-inline', pk=extension.pk) }}");
require(['uploader'], function() {
- $(".screenshot.upload").uploadify("{% url extensions-ajax-screenshot pk=extension.pk %}?geometry=300x200");
- $(".icon.upload").uploadify("{% url extensions-ajax-icon pk=extension.pk %}");
+ $(".screenshot.upload").uploadify("{{ url('extensions-ajax-screenshot', pk=extension.pk) }}?geometry=300x200");
+ $(".icon.upload").uploadify("{{ url('extensions-ajax-icon', pk=extension.pk) }}");
+>>>>>>> Start a port to Jinja/Jingo
});
{% endblock %}
diff --git a/sweettooth/extensions/templates/extensions/list.html b/sweettooth/extensions/templates/extensions/list.html
index 2c4024d..f5b1720 100644
--- a/sweettooth/extensions/templates/extensions/list.html
+++ b/sweettooth/extensions/templates/extensions/list.html
@@ -3,10 +3,10 @@
<ul class="extensions">
{% if extension_list %}
{% for extension in extension_list %}
- {% with extension.latest_version as version %}
+ {% with version=extension.latest_version %}
<li class="extension">
- <h3 class="extension-name"><a href="{% url extensions-detail pk=extension.pk %}" class="title-link"><img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h3>
- <span class="author">by <a href="{% url auth-profile user=extension.creator.username %}">{{ extension.creator }}</a></span>
+ <h3 class="extension-name"><a href="{{ url('extensions-detail', pk=extension.pk) }}" class="title-link"><img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h3>
+ <span class="author">by <a href="{{ url('auth-profile', user=extension.creator.username) }}">{{ extension.creator }}</a></span>
<p class="description">
{{ extension.description }}
</p>
@@ -20,10 +20,9 @@
{% endif %}
</ul>
- {% load paginator %}
- {% if page_obj.has_other_pages %}
+ {% if page_obj.has_other_pages() %}
<div id="paginator">
- {% paginator page_obj %}
+ {{ paginator_html(page_obj) }}
</div>
{% endif %}
{% endblock %}
diff --git a/sweettooth/extensions/templates/extensions/upload.html b/sweettooth/extensions/templates/extensions/upload.html
index ebe8687..e068b30 100644
--- a/sweettooth/extensions/templates/extensions/upload.html
+++ b/sweettooth/extensions/templates/extensions/upload.html
@@ -17,7 +17,7 @@
<form enctype="multipart/form-data" action=""
method="POST">
- {% csrf_token %}
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
{{ form.source }}
<input type="submit" value="Upload extension">
diff --git a/sweettooth/extensions/templatetags/gravatar.py b/sweettooth/extensions/templatetags/gravatar.py
index 6014513..c1f8138 100644
--- a/sweettooth/extensions/templatetags/gravatar.py
+++ b/sweettooth/extensions/templatetags/gravatar.py
@@ -1,8 +1,6 @@
from django import template
import urllib, hashlib
-register = template.Library()
-
GRAVATAR_BASE = "https://secure.gravatar.com/avatar/%s?%s"
@register.simple_tag
diff --git a/sweettooth/extensions/templatetags/paginator.py b/sweettooth/extensions/templatetags/paginator.py
index de5cba1..b774aa9 100644
--- a/sweettooth/extensions/templatetags/paginator.py
+++ b/sweettooth/extensions/templatetags/paginator.py
@@ -2,9 +2,9 @@
from django import template
from django.utils.safestring import mark_safe
-register = template.Library()
+from jingo import register
- register simple_tag
+ register function
def paginator(page_obj, context=3):
number = page_obj.number
context_left = range(max(number-context, 2), number)
diff --git a/sweettooth/ratings/forms.py b/sweettooth/ratings/forms.py
index 000884d..0052f54 100644
--- a/sweettooth/ratings/forms.py
+++ b/sweettooth/ratings/forms.py
@@ -6,10 +6,11 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.comments.forms import CommentForm
from django.utils.encoding import StrAndUnicode, force_unicode
-from django.utils.safestring import mark_safe
from ratings.models import RatingComment
+from jinja2.utils import Markup
+
CHOICES = [(i, str(i+1)) for i in range(5)]
class NoLabelRadioInput(widgets.RadioInput):
@@ -42,7 +43,7 @@ class NoSoapRadio(StrAndUnicode):
def render(self):
"""Outputs a <ul> for this set of radio fields."""
- return mark_safe(u'\n'.join(force_unicode(w) for w in self))
+ return Markup(u'\n'.join(force_unicode(w) for w in self))
class RatingCommentForm(CommentForm):
rating = fields.IntegerField(min_value=0, max_value=4,
diff --git a/sweettooth/ratings/helpers.py b/sweettooth/ratings/helpers.py
new file mode 100644
index 0000000..c81facd
--- /dev/null
+++ b/sweettooth/ratings/helpers.py
@@ -0,0 +1,32 @@
+
+from jingo import register
+from jinja2.utils import Markup
+
+from django.contrib.comments import Comment, get_form
+from django.contrib.contenttypes.models import ContentType
+
+from django.template.loader import render_to_string
+
+ register function
+def rating(value, out_of):
+ parts = []
+ for i in xrange(out_of):
+ attrs = u' disabled'
+ if value == i:
+ attrs += u' checked'
+ parts.append(u'<input type="radio"%s>' % (attrs,))
+ return Markup(u'\n'.join(parts))
+
+ register function
+def get_comments(model):
+ return Comment.objects.for_model(model)
+
+ register function
+def render_comment_form(obj):
+ ctype = ContentType.objects.get_for_model(obj)
+ template_search_list = [
+ "comments/%s/%s/form.html" % (ctype.app_label, ctype.model),
+ "comments/%s/form.html" % ctype.app_label,
+ "comments/form.html"
+ ]
+ return Markup(render_to_string(template_search_list, {"form" : get_form()(obj) }))
diff --git a/sweettooth/review/templates/review/list.html b/sweettooth/review/templates/review/list.html
index eea4a22..931ab5c 100644
--- a/sweettooth/review/templates/review/list.html
+++ b/sweettooth/review/templates/review/list.html
@@ -1,15 +1,15 @@
{% extends "base.html" %}
-{% block title %}Unreviewed Extensions - {{ block.super }}{% endblock %}
+{% block title %}Unreviewed Extensions - {{ super() }}{% endblock %}
{% block body %}
<h2> Unreviewed Extensions </h2>
<ul class="extensions">
{% for version in version_list %}
-{% with version.extension as extension %}
+{% with extension = version.extension %}
<li class="extension">
- <h3 class="extension-name"><a href="{% url review-version pk=version.pk %}"><img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h3>
- <span class="author">by <a href="{% url auth-profile user=extension.creator %}">{{ extension.creator }}</a></span>
+ <h3 class="extension-name"><a href="{{ url('review-version', pk=version.pk) }}"><img src="{{ extension.icon.url }}" class="icon">{{ extension.name }}</a></h3>
+ <span class="author">by <a href="{{ url('auth-profile', user=extension.creator) }}">{{ extension.creator }}</a></span>
<p class="description">
{{ extension.description }}
</p>
diff --git a/sweettooth/review/templates/review/review.html b/sweettooth/review/templates/review/review.html
index c19d197..3dc89f4 100644
--- a/sweettooth/review/templates/review/review.html
+++ b/sweettooth/review/templates/review/review.html
@@ -1,7 +1,6 @@
{% extends "base.html" %}
-{% load thumbnail %}
-{% block title %}Review "{{ version.extension.name }}" - {{ block.super }}{% endblock %}
+{% block title %}Review "{{ version.extension.name }}" - {{ super() }}{% endblock %}
{% block body %}
<h2 class="expanded"> Details Page Preview </h2>
@@ -10,13 +9,13 @@
<img src="{{ extension.icon.url }}" class="icon">
{% if extension.screenshot %}
- {% thumbnail extension.screenshot "300x200" as th %}
- <a href="{{ extension.screenshot.image.url }}" class="screenshot"><img src="{{ th.url }}" /></a>
- {% endthumbnail %}
+ <a href="{{ extension.screenshot.image.url }}" class="screenshot">
+ <img src="{{ thumbnail(extension.screenshot, '300x200').url }}" />
+ </a>
{% endif %}
<h3 class="extension-name">{{ extension.name }}</h3>
- <span class="author">by <a href="{% url auth-profile user=extension.creator %}">{{ extension.creator }}</a></span>
+ <span class="author">by <a href="{{ url('auth-profile', user=extension.creator) }}">{{ extension.creator }}</a></span>
<p class="description">
{{ extension.description }}
</p>
@@ -32,7 +31,7 @@
<div id="files" data-pk="{{ version.pk }}">
</div>
<p>Note: Binary files aren't showed on the web site. To see all
- files, please <a href="{% url review-download pk=version.pk %}">download
+ files, please <a href="{{ url('review-download', pk=version.pk) }}">download
the extension zipfile</a>.</p>
</div>
@@ -53,7 +52,7 @@
<tbody>
{% for version in previous_versions %}
<tr>
- <td><a href="{% url extensions-version-detail ext_pk=extension.pk slug=extension.slug pk=version.pk %}">{{ version.version }}</a></td>
+ <td><a href="{{ url('extensions-version-detail', ext_pk=extension.pk, slug=extension.slug, pk=version.pk) }}">{{ version.version }}</a></td>
<td>
<span class="{{ version.get_status_class }}">{{ version.get_status_display }}</span>
</td>
@@ -71,16 +70,16 @@
<div id="previous_reviews">
{% for review in previous_reviews %}
<div class="review">
- <a class="review-author" href="{% url auth-profile user=review.reviewer.username %}">{{ review.reviewer }}</a>
+ <a class="review-author" href="{{ url('auth-profile', user=review.reviewer.username) }}">{{ review.reviewer }}</a>
{% if review.changelog %}
<span class="{{ review.changelog.get_newstatus_class }}">{{ review.changelog.get_newstatus_display|lower }}</span>
{% else %}
posted a review
{% endif %}
- <abbr class="timestamp" title="{{ review.date|date:"c" }}">{{ review.date|date:"F j, Y" }}</abbr>
+ <abbr class="timestamp" title="{{ review.date.isoformat() }}">{{ review.date|datetime("%B %d, %Y") }}</abbr>
<blockquote>{{ review.comments }}</blockquote>
</div>
- {% empty %}
+ {% else %}
<p>No reviews.</p>
{% endfor %}
</div>
@@ -91,9 +90,9 @@
{% endblock %}
-{% block js-main %}review-main{% endblock %}
+{% block js_main %}review-main{% endblock %}
{% block head %}
- {{ block.super }}
+ {{ super() }}
<link rel="stylesheet" href="/static/css/review.css" />
{% endblock %}
diff --git a/sweettooth/review/templates/review/review_reviewer.html b/sweettooth/review/templates/review/review_reviewer.html
index 9d63077..6fad260 100644
--- a/sweettooth/review/templates/review/review_reviewer.html
+++ b/sweettooth/review/templates/review/review_reviewer.html
@@ -1,13 +1,13 @@
{% extends "review/review.html" %}
{% block extra %}
-{{ block.super }}
+{{ super() }}
<h2 class="expanded"> Review </h2>
<div id="review">
- <form id="review_form" action="{% url review-submit pk=version.pk %}" method="POST">
- {% csrf_token %}
+ <form id="review_form" action="{{ url('review-submit', pk=version.pk) }}" method="POST">
+ <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
<textarea id="comments" name="comments"></textarea>
{% if can_approve %}
<select name="status">
diff --git a/sweettooth/settings.py b/sweettooth/settings.py
index d49c8e8..2694440 100644
--- a/sweettooth/settings.py
+++ b/sweettooth/settings.py
@@ -76,11 +76,17 @@ SECRET_KEY = 'tv(d+lom-sa^de5i#ab)(g^3249tbzssizuvh8m9_lwppdn1bw'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
+ 'jingo.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
+JINJA_CONFIG = {'extensions': ['jinja2.ext.i18n',
+ 'jinja2.ext.with_']}
+
+JINGO_EXCLUDE_APPS = ['comments']
+
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
diff --git a/sweettooth/templates/base.html b/sweettooth/templates/base.html
index 0e59e12..b78325f 100644
--- a/sweettooth/templates/base.html
+++ b/sweettooth/templates/base.html
@@ -8,36 +8,32 @@
<title>{% block title %}GNOME Shell Extensions{% endblock %}</title>
<script>
window._SW = function() {
-{% block document-ready %}{% endblock %}
+{% block document_ready %}{% endblock %}
};
</script>
<script src="/static/js/jquery.js"></script>
- <script data-main="/static/js/{% block js-main %}main{% endblock %}.js" src="/static/js/require.js"></script>
+ <script data-main="/static/js/{% block js_main %}main{% endblock %}.js" src="/static/js/require.js"></script>
</head>
<body>
<div id="global_domain_bar">
<div class="maxwidth">
<div class="tab">
- {% spaceless %}
-
<a class="root" href="http://www.gnome.org/">GNOME.org</a>
{% if n_unreviewed_extensions %}
- <a id="unreviewed_counter" href="{% url review-list %}">{{ n_unreviewed_extensions }}</a>
+ <a id="unreviewed_counter" href="{{ url('review-list') }}">{{ n_unreviewed_extensions }}</a>
{% endif %}
- {% if request.user.is_authenticated %}
+ {% if request.user.is_authenticated() %}
<a class="user" href="#">{{ request.user.username }}</a>
{% else %}
- <a class="user" href="{% url auth-login %}">Login</a>
+ <a class="user" href="{{ url('auth-login') }}">Login</a>
{% endif %}
-
- {% endspaceless %}
</div>
- {% if request.user.is_authenticated %}
+ {% if request.user.is_authenticated() %}
<div class="user_settings">
<ul>
- <li><a href="{% url auth-profile user=request.user.username %}">Your profile</a></li>
- <li><a href="{% url auth-settings user=request.user.username %}">Settings</a></li>
- <li><a href="{% url auth-logout %}">Log out</a></li>
+ <li><a href="{{ url('auth-profile', user=request.user.username) }}">Your profile</a></li>
+ <li><a href="{{ url('auth-settings', user=request.user.username) }}">Settings</a></li>
+ <li><a href="{{ url('auth-logout') }}">Log out</a></li>
</ul>
</div>
{% else %}
@@ -52,9 +48,9 @@ window._SW = function() {
<h1><a href="/"><img src="/static/images/foot.png" alt="GNOME" />Shell Extensions</a><span class="alpha-banner">Alpha!</span></h1>
<ul id="globalnav" class="{% block navclass %}{% endblock %}">
- <li class="main"><a href="{% url extensions-index %}">Extensions</a></li>
- <li class="upload"><a href="{% url extensions-upload-file %}">Add yours</a></li>
- <li class="local"><a href="{% url extensions-local %}">Installed extensions</a></li>
+ <li class="main"><a href="{{ url('extensions-index') }}">Extensions</a></li>
+ <li class="upload"><a href="{{ url('extensions-upload-file') }}">Add yours</a></li>
+ <li class="local"><a href="{{ url('extensions-local') }}">Installed extensions</a></li>
</ul>
<!-- <div class="right"> -->
@@ -73,7 +69,7 @@ window._SW = function() {
<p class="message {{ message.tags }}">{{ message }}</p>
{% endfor %}
- {% block extra-messages %}
+ {% block extra_messages %}
{% endblock %}
</div>
{% block body %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]