diff gpp/downloads/views.py @ 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 41411066b16d
line wrap: on
line diff
--- 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))