changeset 383:b2b37cdd020a

Fixing #189; 500 error when deleting forum topic subscription.
author Brian Neal <bgneal@gmail.com>
date Wed, 16 Mar 2011 01:19:45 +0000
parents a1b03de20345
children 957955279a15
files gpp/forums/views/favorites.py gpp/forums/views/subscriptions.py
diffstat 2 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/views/favorites.py	Wed Mar 09 02:39:24 2011 +0000
+++ b/gpp/forums/views/favorites.py	Wed Mar 16 01:19:45 2011 +0000
@@ -47,10 +47,9 @@
             for topic in user.favorite_topics.filter(id__in=delete_ids):
                 user.favorite_topics.remove(topic)
 
-        page_num = request.POST.get('page', 1)
-    else:
-        page_num = request.GET.get('page', 1)
+        return HttpResponseRedirect(reverse("forums-manage_favorites"))
 
+    page_num = request.GET.get('page', 1)
     topics = user.favorite_topics.select_related().order_by('-update_date')
     paginator = DiggPaginator(topics, 20, body=5, tail=2, margin=3, padding=2)
     try:
--- a/gpp/forums/views/subscriptions.py	Wed Mar 09 02:39:24 2011 +0000
+++ b/gpp/forums/views/subscriptions.py	Wed Mar 16 01:19:45 2011 +0000
@@ -94,7 +94,7 @@
     topic = get_object_or_404(Topic, id=topic_id)
     try:
         sub = Subscription.objects.get(topic=topic, user=request.user)
-    except Subscriptions.DoesNotExist:
+    except Subscription.DoesNotExist:
         pass
     else:
         sub.delete()
@@ -121,20 +121,19 @@
     user = request.user
     if request.method == "POST":
         if request.POST.get('delete_all'):
-            user.subscriptions.clear()
+            Subscription.objects.filter(user=user).delete()
         else:
             delete_ids = request.POST.getlist('delete_ids')
             try:
                 delete_ids = [int(id) for id in delete_ids]
             except ValueError:
                 raise Http404
-            for topic in user.subscriptions.filter(id__in=delete_ids):
-                user.subscriptions.remove(topic)
 
-        page_num = request.POST.get('page', 1)
-    else:
-        page_num = request.GET.get('page', 1)
+            Subscription.objects.filter(user=user, topic__in=delete_ids).delete()
 
+        return HttpResponseRedirect(reverse("forums-manage_subscriptions"))
+
+    page_num = request.GET.get('page', 1)
     topics = user.subscriptions.select_related().order_by('-update_date')
     paginator = DiggPaginator(topics, 20, body=5, tail=2, margin=3, padding=2)
     try: