Commits

luke  committed e06c11e

[project @ 336]
Fixed bug with 404s when deleting messages or moving messages around.

  • Participants
  • Parent commits 23bce46

Comments (0)

Files changed (1)

File cciw/cciwmain/views/members.py

 
 from datetime import datetime, timedelta
 import re
+import math
 
 def index(request):
     """
                         action(msg)
                     except Message.DoesNotExist:
                         pass
+        message_count = member.messages_received.filter(box=box).count()
+        page = request.GET.get('page', 1)
+        last_page = int(math.ceil(float(message_count)/settings.MEMBERS_PAGINATE_MESSAGES_BY))
+        if page > last_page:
+            # User may have deleted/moved everything on the last page,
+            # so need to redirect to avoid a 404
+            return HttpResponseRedirect(request.path + "?page=%s" % last_page)
+            
     
     # Context
     extra_context = standard_extra_context()
     return list_detail.object_list(request, messages,
         extra_context=extra_context,
         template_name='cciw/members/messages/index.html',
-        paginate_by=20,
+        paginate_by=settings.MEMBERS_PAGINATE_MESSAGES_BY,
         allow_empty=True)
 
 def inbox(request, user_name):