From 4442680cf6f928baae58646f73862db93dca63f5 Mon Sep 17 00:00:00 2001 From: Les Orchard Date: Sun, 16 Oct 2011 17:11:41 -0400 Subject: [PATCH] Fixes and tweaks for profiles and awards list * Added by-badge awards list view URL * Recent awards listed on badge detail page * Showing user names as unicode() * Using user.get_absolute_url() everywhere for profile links --- badger/templates/badger/awards_by_user.html | 2 +- badger/templates/badger/awards_list.html | 6 +++++- badger/templates/badger/badge_detail.html | 12 ++++++------ badger/templates/badger/home.html | 1 - .../badger/includes/award_as_user.html | 2 +- .../templates/badger/includes/award_full.html | 6 +++--- .../templates/badger/includes/badge_full.html | 2 ++ badger/urls.py | 16 +++++++++------- badger/views.py | 19 +++++++++++++++---- 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/badger/templates/badger/awards_by_user.html b/badger/templates/badger/awards_by_user.html index 798b26f..ba1ed1e 100644 --- a/badger/templates/badger/awards_by_user.html +++ b/badger/templates/badger/awards_by_user.html @@ -10,7 +10,7 @@ {% block content %}
-

Awards for {{user}}

+

Awards for {{ user }}

{% include "badger/includes/awards_list.html" %}
{% endblock %} diff --git a/badger/templates/badger/awards_list.html b/badger/templates/badger/awards_list.html index ffbeb66..9f1fbd7 100644 --- a/badger/templates/badger/awards_list.html +++ b/badger/templates/badger/awards_list.html @@ -11,7 +11,11 @@ {% block content %}
-

Awards

+ {% if badge %} +

Awards for {{ badge }}

+ {% else: %} +

Recent Awards

+ {% endif %} {% include "badger/includes/awards_list.html" %}
diff --git a/badger/templates/badger/badge_detail.html b/badger/templates/badger/badge_detail.html index becfeda..f30bd2b 100644 --- a/badger/templates/badger/badge_detail.html +++ b/badger/templates/badger/badge_detail.html @@ -16,15 +16,15 @@

Badge detail

{% include "badger/includes/badge_full.html" %} -{% if awards %} +{% if award_list %}

Recent awards

- {% endif %} {% endblock %} diff --git a/badger/templates/badger/home.html b/badger/templates/badger/home.html index a03d574..a04e62b 100644 --- a/badger/templates/badger/home.html +++ b/badger/templates/badger/home.html @@ -40,7 +40,6 @@
  • More... -
  • diff --git a/badger/templates/badger/includes/award_as_user.html b/badger/templates/badger/includes/award_as_user.html index 3607dab..9b4c8d5 100644 --- a/badger/templates/badger/includes/award_as_user.html +++ b/badger/templates/badger/includes/award_as_user.html @@ -1,4 +1,4 @@ {% set user = award.user %}
    - {{ user.username }} + {{ user }}
    diff --git a/badger/templates/badger/includes/award_full.html b/badger/templates/badger/includes/award_full.html index cc00eb8..1a84ec4 100644 --- a/badger/templates/badger/includes/award_full.html +++ b/badger/templates/badger/includes/award_full.html @@ -1,9 +1,9 @@
    Awarded to:
    -
    {{ user.username }}
    +
    {{ award.user }}
    Awarded by:
    -
    {{ award.creator }}
    Issued on:
    {{ award.created }}
    diff --git a/badger/templates/badger/includes/badge_full.html b/badger/templates/badger/includes/badge_full.html index 6a8bdb1..4496658 100644 --- a/badger/templates/badger/includes/badge_full.html +++ b/badger/templates/badger/includes/badge_full.html @@ -12,6 +12,8 @@
    Description:
    {{ badge.description }}
    {% endif %} +
    Creator:
    +
    {{ badge.creator }}
    Created:
    {{ badge.created }}
    Modified:
    diff --git a/badger/urls.py b/badger/urls.py index a112919..d78d4a5 100644 --- a/badger/urls.py +++ b/badger/urls.py @@ -11,26 +11,28 @@ urlpatterns = patterns('badger.views', url(r'^$', 'badges_list', name='badger.badges_list'), url(r'^awards/?', 'awards_list', name='badger.awards_list'), - url(r'^detail/(?P[^/]+)/awards/(?P[^\.]+)\.json$', 'award_detail', + url(r'^badge/(?P[^/]+)/awards/?$', 'awards_list', + name='badger.awards_list_for_badge'), + url(r'^badge/(?P[^/]+)/awards/(?P[^\.]+)\.json$', 'award_detail', kwargs=dict(format="json"), name='badger.award_detail_json'), - url(r'^detail/(?P[^/]+)/awards/(?P[^/]+)/?$', 'award_detail', + url(r'^badge/(?P[^/]+)/awards/(?P[^/]+)/?$', 'award_detail', name='badger.award_detail'), - url(r'^detail/(?P[^/]+);award', 'award_badge', + url(r'^badge/(?P[^/]+);award', 'award_badge', name='badger.award_badge'), - url(r'^detail/(?P[^\.]+)\.json$', 'detail', + url(r'^badge/(?P[^\.]+)\.json$', 'detail', kwargs=dict(format="json"), name='badger.detail_json'), - url(r'^detail/(?P[^/]+)/?$', 'detail', + url(r'^badge/(?P[^/]+)/?$', 'detail', name='badger.detail'), - url(r'^detail/(?P[^/]+)/awards/?$', 'awards_by_badge', + url(r'^badge/(?P[^/]+)/awards/?$', 'awards_by_badge', name='badger.awards_by_badge'), url(r'^users/(?P[^/]+)/awards/?$', 'awards_by_user', name='badger.awards_by_user'), url(r'^feeds/(?P[^/]+)/awards/?$', AwardsRecentFeed(), name="badger.feeds.awards_recent"), - url(r'^feeds/(?P[^/]+)/detail/(?P[^/]+)/awards/?$', + url(r'^feeds/(?P[^/]+)/badge/(?P[^/]+)/awards/?$', AwardsByBadgeFeed(), name="badger.feeds.awards_by_badge"), url(r'^feeds/(?P[^/]+)/users/(?P[^/]+)/awards/?$', AwardsByUserFeed(), name="badger.feeds.awards_by_user"), diff --git a/badger/views.py b/badger/views.py index 5f30630..25d92b6 100644 --- a/badger/views.py +++ b/badger/views.py @@ -48,6 +48,7 @@ MAX_RECENT = 9 def home(request): + """Badger home page""" return render_to_response('badger/home.html', dict( badge_list=Badge.objects.order_by('-modified').all()[:MAX_RECENT], award_list=Award.objects.order_by('-modified').all()[:MAX_RECENT], @@ -55,7 +56,7 @@ def home(request): def badges_list(request): - """Badger index page""" + """Badges list page""" queryset = Badge.objects.order_by('-modified').all() return object_list(request, queryset, paginate_by=BADGE_PAGE_SIZE, allow_empty=True, @@ -77,7 +78,7 @@ def detail(request, slug, format="html"): return resp else: return render_to_response('badger/badge_detail.html', dict( - badge=badge, awards=awards, + badge=badge, award_list=awards, ), context_instance=RequestContext(request)) @@ -105,10 +106,20 @@ def award_badge(request, slug): @require_GET -def awards_list(request): - queryset = Award.objects.order_by('-modified').all() +def awards_list(request, slug=None): + queryset = Award.objects + if not slug: + badge = None + else: + badge = get_object_or_404(Badge, slug=slug) + queryset = queryset.filter(badge=badge) + queryset = queryset.order_by('-modified').all() + return object_list(request, queryset, paginate_by=BADGE_PAGE_SIZE, allow_empty=True, + extra_context=dict( + badge=badge + ), template_object_name='award', template_name='badger/awards_list.html')