comparison gpp/forums/views/subscriptions.py @ 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 ee451ad46af1
children 9fcd366f22dc
comparison
equal deleted inserted replaced
382:a1b03de20345 383:b2b37cdd020a
92 def unsubscribe_topic(request, topic_id): 92 def unsubscribe_topic(request, topic_id):
93 """Unsubscribe the user to the requested topic.""" 93 """Unsubscribe the user to the requested topic."""
94 topic = get_object_or_404(Topic, id=topic_id) 94 topic = get_object_or_404(Topic, id=topic_id)
95 try: 95 try:
96 sub = Subscription.objects.get(topic=topic, user=request.user) 96 sub = Subscription.objects.get(topic=topic, user=request.user)
97 except Subscriptions.DoesNotExist: 97 except Subscription.DoesNotExist:
98 pass 98 pass
99 else: 99 else:
100 sub.delete() 100 sub.delete()
101 return HttpResponseRedirect( 101 return HttpResponseRedirect(
102 reverse("forums-subscription_status", args=[topic.id])) 102 reverse("forums-subscription_status", args=[topic.id]))
119 """Display a user's topic subscriptions, and allow them to be deleted.""" 119 """Display a user's topic subscriptions, and allow them to be deleted."""
120 120
121 user = request.user 121 user = request.user
122 if request.method == "POST": 122 if request.method == "POST":
123 if request.POST.get('delete_all'): 123 if request.POST.get('delete_all'):
124 user.subscriptions.clear() 124 Subscription.objects.filter(user=user).delete()
125 else: 125 else:
126 delete_ids = request.POST.getlist('delete_ids') 126 delete_ids = request.POST.getlist('delete_ids')
127 try: 127 try:
128 delete_ids = [int(id) for id in delete_ids] 128 delete_ids = [int(id) for id in delete_ids]
129 except ValueError: 129 except ValueError:
130 raise Http404 130 raise Http404
131 for topic in user.subscriptions.filter(id__in=delete_ids):
132 user.subscriptions.remove(topic)
133 131
134 page_num = request.POST.get('page', 1) 132 Subscription.objects.filter(user=user, topic__in=delete_ids).delete()
135 else:
136 page_num = request.GET.get('page', 1)
137 133
134 return HttpResponseRedirect(reverse("forums-manage_subscriptions"))
135
136 page_num = request.GET.get('page', 1)
138 topics = user.subscriptions.select_related().order_by('-update_date') 137 topics = user.subscriptions.select_related().order_by('-update_date')
139 paginator = DiggPaginator(topics, 20, body=5, tail=2, margin=3, padding=2) 138 paginator = DiggPaginator(topics, 20, body=5, tail=2, margin=3, padding=2)
140 try: 139 try:
141 page_num = int(page_num) 140 page_num = int(page_num)
142 except ValueError: 141 except ValueError: