Commits

Dan Carroll committed 1b2441b

Switch activity list to using /page/<num/ URL instead of ?page=<num> parameter

Comments (0)

Files changed (2)

mysite/activitysync/views.py

 from django.http import Http404
-from django.shortcuts import render_to_response
+from django.shortcuts import redirect, render_to_response
 from django.template import RequestContext
 
 from activitysync.models import Activity
 from activitysync.paginator import InfinitePaginator
 
-def activity(request):
+def activity(request, page="1", explicit_page_request=False):
+    # Make sure page parameter is an integer
+    try:
+        page = int(page)
+    except:
+        raise Http404
+
+    # Make sure we only have one canonical first page
+    if explicit_page_request and page == 1:
+        return redirect('main_activity')
+
+    # Previous URL uses GET parameter 'page', so let's check
+    # for that and redirect to new view if necessary
+    if not explicit_page_request:
+        try:
+            requestNum = request.GET['page']
+            if requestNum != None and requestNum.isdigit():
+                return redirect('activity_paged', page=requestNum)
+        except KeyError:
+            pass
+    
     activity_list = Activity.objects.published().defer("username", "author", "comments", "guid")
-
-    # Make sure page request is an int.  If not, deliver first page.
-    try:
-        page = int(request.GET.get('page', '1'))
-    except ValueError:
-        page = 1
+    paginator = InfinitePaginator(activity_list, 25)
     
-    paginator = InfinitePaginator(activity_list, 25)
     try:
         activities = paginator.page(page)
     except:
     
     # Main sections
     url(r'^activity/$', view='activitysync.views.activity', name='main_activity'),
+    url(r'^activity/page/(?P<page>\d+)/$', view='activitysync.views.activity', kwargs={'explicit_page_request': True}, name='activity_paged'),
     url(r'^blog/', include('mysite.blog.urls')),
     
     # RSS feeds