Add view and feed listing badges created by user

This commit is contained in:
Les Orchard 2011-10-20 22:39:12 -04:00 коммит произвёл Les Orchard
Родитель efec5fef12
Коммит 4b7a568626
4 изменённых файлов: 51 добавлений и 1 удалений

Просмотреть файл

@ -49,9 +49,28 @@ class BadgesFeed(BaseFeed):
reverse('badger.views.detail',
args=(obj.slug, )))
class BadgesRecentFeed(BadgesFeed):
def items(self):
return (Badge.objects
.order_by('-created')
.all()[:MAX_FEED_ITEMS])
class BadgesByUserFeed(BadgesFeed):
"""Feed of badges recently created by a user"""
def get_object(self, request, format, username):
super(BadgesByUserFeed, self).get_object(request, format)
user = get_object_or_404(User, username=username)
self.title = _("Badges recently created by %s") % user.username
self.link = request.build_absolute_uri(
reverse('badger_multiplayer.views.badges_by_user', args=(user.username,)))
return user
def items(self, user):
return (Badge.objects
.filter(creator=user)
.order_by('-created')
.all()[:MAX_FEED_ITEMS])

Просмотреть файл

@ -0,0 +1,16 @@
{% extends "badger/base.html" %}
{% block pageid %}badges_by_user{% endblock %}
{% block extrahead %}
<link rel="alternate" type="application/atom+xml"
title="{{ _('Recent awards') }}"
href="{{ url('badger_multiplayer.feeds.badges_by_user', 'atom', user.username) }}" />
{% endblock %}
{% block content %}
<section class="badge_list">
<h2>Badges created by {{ user }}</h2>
{% include "badger/includes/badges_list.html" %}
</section>
{% endblock %}

Просмотреть файл

@ -4,7 +4,7 @@ from django.conf import settings
from django.views.generic.list_detail import object_list
from django.views.generic.simple import direct_to_template
from .feeds import BadgesRecentFeed
from .feeds import BadgesRecentFeed, BadgesByUserFeed
urlpatterns = patterns('badger_multiplayer.views',
@ -16,7 +16,12 @@ urlpatterns = patterns('badger_multiplayer.views',
name='badger_multiplayer.badge_edit'),
url(r'^badge/(?P<slug>[^/]+)/nominations/(?P<id>[^/]+)/?$', 'nomination_detail',
name='badger.nomination_detail'),
url(r'^users/(?P<username>[^/]+)/badges/?$', 'badges_by_user',
name='badger_multiplayer.badges_by_user'),
url(r'^feeds/(?P<format>[^/]+)/badges/?$', BadgesRecentFeed(),
name="badger_multiplayer.feeds.badges_recent"),
url(r'^feeds/(?P<format>[^/]+)/users/(?P<username>[^/]+)/badges/?$',
BadgesByUserFeed(),
name="badger_multiplayer.feeds.badges_by_user"),
)

Просмотреть файл

@ -40,6 +40,16 @@ from badger_multiplayer.forms import (BadgeNewForm, BadgeEditForm,
BadgeSubmitNominationForm)
@require_GET
def badges_by_user(request, username):
"""Badges created by user"""
user = get_object_or_404(User, username=username)
badges = Badge.objects.filter(creator=user)
return render_to_response('badger_multiplayer/badges_by_user.html', dict(
user=user, badge_list=badges,
), context_instance=RequestContext(request))
@require_http_methods(['GET', 'POST'])
@login_required
def create(request):