changeset 243:7ddd60164245

For #93: remove the page number from the URL. This commit fixes the shoutbox and member list. It also contains a change to downloads to add pagination to the new, popular, and highest rated views.
author Brian Neal <bgneal@gmail.com>
date Thu, 16 Sep 2010 01:06:43 +0000
parents 7e8d2dda99e3
children a61b1c598001
files gpp/bio/urls.py gpp/bio/views.py gpp/downloads/views.py gpp/shoutbox/urls.py gpp/shoutbox/views.py gpp/templates/base.html gpp/templates/bio/members.html gpp/templates/downloads/download_summary.html gpp/templates/shoutbox/shoutbox.html
diffstat 9 files changed, 60 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/urls.py	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/bio/urls.py	Thu Sep 16 01:06:43 2010 +0000
@@ -2,9 +2,9 @@
 from django.conf.urls.defaults import *
 
 urlpatterns = patterns('bio.views',
-    url(r'^members/(?P<type>user|date)/page/(?P<page>\d+)/$', 
+    url(r'^members/(?P<type>user|date)/$', 
         'member_list', 
-        name='bio-members_full'),
+        name='bio-member_list'),
     url(r'^members/search/$', 'member_search', name='bio-member_search'),
     url(r'^me/$', 'my_profile', name='bio-me'),
     url(r'^view/(?P<username>\w{1,30})/$', 'view_profile', name='bio-view_profile'),
@@ -13,11 +13,3 @@
     url(r'^avatar/$', 'change_avatar', name='bio-change_avatar'),
     url(r'^flag/(\d+)/$', 'flag_profile', name='bio-flag_profile'),
 )
-
-urlpatterns += patterns('django.views.generic.simple',
-    url(r'^members/$', 
-        'redirect_to', 
-        {'url': '/profile/members/user/page/1/'},
-        name='bio-members'),
-)
-
--- a/gpp/bio/views.py	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/bio/views.py	Thu Sep 16 01:06:43 2010 +0000
@@ -10,6 +10,7 @@
 from django.http import HttpResponse
 from django.http import HttpResponseBadRequest
 from django.http import HttpResponseRedirect
+from django.http import Http404
 from django.core.paginator import InvalidPage
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
@@ -28,11 +29,12 @@
 from bio.forms import SearchUsersForm
 from core.paginator import DiggPaginator
 from core.functions import email_admins
+from core.functions import get_page
 
 #######################################################################
 
 @login_required
-def member_list(request, type='user', page=1):
+def member_list(request, type='user'):
     """
     This view displays the member list. Only active members are displayed.
     """
@@ -44,8 +46,9 @@
     num_members = qs.count()
 
     paginator = DiggPaginator(qs, 20, body=5, tail=3, margin=3, padding=2)
+    page = get_page(request.GET)
     try:
-        the_page = paginator.page(int(page))
+        the_page = paginator.page(page)
     except InvalidPage:
         raise Http404
 
--- a/gpp/downloads/views.py	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/downloads/views.py	Thu Sep 16 01:06:43 2010 +0000
@@ -84,10 +84,20 @@
 
 @login_required
 def new(request):
-    downloads = Download.public_objects.order_by('-date_added')[:DLS_PER_PAGE]
+    """Display new downloads with pagination."""
+
+    downloads = Download.public_objects.order_by('-date_added')
+
+    paginator = create_paginator(downloads)
+    page = get_page(request.GET)
+    try:
+        the_page = paginator.page(page)
+    except InvalidPage:
+        raise Http404
+
     return render_to_response('downloads/download_summary.html', {
-        'downloads' : downloads,
-        'title' : 'Newest Downloads',
+        'page': the_page,
+        'title': 'Newest Downloads',
         }, 
         context_instance = RequestContext(request))
 
@@ -95,10 +105,20 @@
 
 @login_required
 def popular(request):
-    downloads = Download.public_objects.order_by('-hits')[:DLS_PER_PAGE]
+    """Display popular downloads with pagination."""
+
+    downloads = Download.public_objects.order_by('-hits')
+
+    paginator = create_paginator(downloads)
+    page = get_page(request.GET)
+    try:
+        the_page = paginator.page(page)
+    except InvalidPage:
+        raise Http404
+
     return render_to_response('downloads/download_summary.html', {
-        'downloads' : downloads,
-        'title' : 'Popular Downloads',
+        'page': the_page,
+        'title': 'Popular Downloads',
         }, 
         context_instance = RequestContext(request))
 
@@ -106,10 +126,19 @@
 
 @login_required
 def rating(request):
-    downloads = Download.public_objects.order_by('-average_score')[:DLS_PER_PAGE]
+    """Display downloads by rating with pagination."""
+
+    downloads = Download.public_objects.order_by('-average_score')
+    paginator = create_paginator(downloads)
+    page = get_page(request.GET)
+    try:
+        the_page = paginator.page(page)
+    except InvalidPage:
+        raise Http404
+
     return render_to_response('downloads/download_summary.html', {
-        'downloads' : downloads,
-        'title' : 'Highest Rated Downloads',
+        'page': the_page,
+        'title': 'Highest Rated Downloads',
         }, 
         context_instance = RequestContext(request))
 
--- a/gpp/shoutbox/urls.py	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/shoutbox/urls.py	Thu Sep 16 01:06:43 2010 +0000
@@ -11,7 +11,5 @@
     url(r'^shout/$', 'shout', name='shoutbox-shout'),
     url(r'^text/$', 'text', name='shoutbox-text'),
     url(r'^view/(\d+)/$', 'view_shout', name='shoutbox-view'),
-    url(r'^view/history/(?P<page>\d+)/$', 'view_history', name='shoutbox-history'),
+    url(r'^view/history/$', 'view_history', name='shoutbox-history'),
 )
-
-# vim: ts=4 sw=4
--- a/gpp/shoutbox/views.py	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/shoutbox/views.py	Thu Sep 16 01:06:43 2010 +0000
@@ -16,6 +16,7 @@
 
 from core.paginator import DiggPaginator
 from core.functions import email_admins
+from core.functions import get_page
 from shoutbox.forms import ShoutBoxForm
 from shoutbox.models import Shout
 from shoutbox.models import ShoutFlag
@@ -51,12 +52,13 @@
        context_instance = RequestContext(request))
 
 
-def view_history(request, page=1):
+def view_history(request):
     """This view allows one to view the shoutbox history."""
     paginator = DiggPaginator(Shout.objects.all().select_related(), 
             SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2)
+    page = get_page(request.GET)
     try:
-        the_page = paginator.page(int(page))
+        the_page = paginator.page(page)
     except InvalidPage:
         raise Http404
 
--- a/gpp/templates/base.html	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/templates/base.html	Thu Sep 16 01:06:43 2010 +0000
@@ -59,7 +59,7 @@
       <li><a href="{% url donations-index %}">Donations</a></li>
       <li><a href="{% url forums-index %}">Forums</a></li>
       <li><a href="{% url irc-main %}">IRC</a></li>
-      <li><a href="{% url bio-members %}">Member List</a></li>
+      <li><a href="{% url bio-member_list type='user' %}">Member List</a></li>
       <li><a href="{% url membermap-index %}">Member Map</a></li>
       <li><a href="{% url messages-inbox %}">Private Messages</a></li>
       <li><a href="{% url podcast-main %}">Podcast</a></li>
--- a/gpp/templates/bio/members.html	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/templates/bio/members.html	Thu Sep 16 01:06:43 2010 +0000
@@ -14,9 +14,9 @@
 </p>
 {% if page.object_list %}
 <ul class="tab-nav">
-   <li><a href="{% url bio-members_full type='user' page=1 %}"
+   <li><a href="{% url bio-member_list type='user' %}"
       {% ifequal type "user" %}class="active" {% endifequal %}>User</a></li>
-   <li><a href="{% url bio-members_full type='date' page=1 %}"
+   <li><a href="{% url bio-member_list type='date' %}"
       {% ifequal type "date" %}class="active" {% endifequal %}>Date</a></li>
 </ul>
 
--- a/gpp/templates/downloads/download_summary.html	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/templates/downloads/download_summary.html	Thu Sep 16 01:06:43 2010 +0000
@@ -3,6 +3,8 @@
 {% block title %}{{ title }}{% endblock %}
 {% block custom_css %}
 <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/downloads.css" />
+<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/tab-nav.css" />
+<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/pagination.css" />
 {% endblock %}
 {% block custom_js %}
 <script type="text/javascript" src="{{ MEDIA_URL }}js/downloads/rating.js"></script>
@@ -12,12 +14,14 @@
 {% include 'downloads/navigation.html' %}
 <h3>{{ title }}</h3>
 
-{% if downloads %}
+{% if page.object_list %}
+{% include 'core/pagination.html' %}
 <dl>
-{% for download in downloads %}
+{% for download in page.object_list %}
    {% include 'downloads/download.html' %}
 {% endfor %}
 </dl>
+{% include 'core/pagination.html' %}
 {% else %}
 <p>No downloads available at this time.</p>
 {% endif %}
--- a/gpp/templates/shoutbox/shoutbox.html	Wed Sep 15 03:24:01 2010 +0000
+++ b/gpp/templates/shoutbox/shoutbox.html	Thu Sep 16 01:06:43 2010 +0000
@@ -10,7 +10,7 @@
       </p>
    {% endfor %}
 </div>
-<center><a href="{% url shoutbox-history page=1 %}">Shout History</a></center>
+<center><a href="{% url shoutbox-history %}">Shout History</a></center>
 {% if user.is_authenticated %}
 <center>
 <div>