review_list view
This commit is contained in:
Родитель
1b5105ed1a
Коммит
87a006d00f
|
@ -0,0 +1,7 @@
|
|||
<ul>
|
||||
<li>
|
||||
<a href="{{ addon.get_absolute_url() }}">
|
||||
{{ _('Back to {0}')|f(addon.name) }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
|
@ -0,0 +1,26 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="primary" role="main">
|
||||
{% set addon_name = addon.name %}
|
||||
<h2>{{ _('Reviews for {0}')|f(addon.name) }}</h2>
|
||||
|
||||
{% include "reviews/navigation.html" %}
|
||||
<hr>
|
||||
{% for review in reviews.object_list %}
|
||||
<div class="item review" id="review-{{ review.id }}">
|
||||
<h3>{{ review.title }}</h3>
|
||||
<div class="reviewed-on">
|
||||
{{ review.rating|stars }}
|
||||
{% trans user=review.user|user_link, date=review.created|datetime %}
|
||||
by {{ user }} on {{ date }}
|
||||
{% endtrans %}
|
||||
</div>
|
||||
<p>{{ review.body|nl2br }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{{ reviews|paginator }}
|
||||
<hr>
|
||||
{% include "reviews/navigation.html" %}
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -0,0 +1,19 @@
|
|||
import math
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
import jinja2
|
||||
|
||||
from jingo import register
|
||||
|
||||
|
||||
@register.filter
|
||||
def stars(num):
|
||||
if num is None:
|
||||
return _('Not yet rated')
|
||||
else:
|
||||
stars = math.ceil(num)
|
||||
msg = _('Rated %s out of 5 stars') % stars
|
||||
s = ('<span class="stars stars-{num}" title="{msg}">{msg}</span>'
|
||||
% {'num': stars, 'msg': msg})
|
||||
return jinja2.Markup(s)
|
|
@ -0,0 +1,7 @@
|
|||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^display/(\d+)$', views.review_list, name='reviews.list'),
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
|
||||
import jingo
|
||||
|
||||
import amo
|
||||
from addons.models import Addon
|
||||
from versions.models import Version
|
||||
|
||||
from .models import Review
|
||||
|
||||
|
||||
def review_list(request, addon_id):
|
||||
addon = get_object_or_404(Addon, id=addon_id)
|
||||
|
||||
versions = Version.objects.filter(addon=addon)
|
||||
q = Review.objects.filter(version__in=versions).order_by('-created')
|
||||
reviews = amo.paginate(request, q)
|
||||
return jingo.render(request, 'reviews/review_list.html',
|
||||
{'addon': addon, 'reviews': reviews})
|
7
urls.py
7
urls.py
|
@ -1,11 +1,16 @@
|
|||
from django.conf import settings
|
||||
from django.conf.urls.defaults import *
|
||||
from django.conf.urls.defaults import patterns, url, include
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^$', 'jingo.views.direct_to_template',
|
||||
{'template': 'base.html'}, name='home'),
|
||||
|
||||
# Reviews.
|
||||
('^reviews/', include('reviews.urls')),
|
||||
)
|
||||
|
||||
|
||||
if settings.DEBUG:
|
||||
# Remove leading and trailing slashes so the regex matches.
|
||||
media_url = settings.MEDIA_URL.lstrip('/').rstrip('/')
|
||||
|
|
Загрузка…
Ссылка в новой задаче