comparison gpp/forums/views/subscriptions.py @ 459:9d3bd7304050

Fixing #221. Also combined all permissions checks into a new module, permissions.py. This allows us to cache user, category, and forum groups information since it rarely changes.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Jul 2011 23:35:45 +0000
parents 9fcd366f22dc
children 82b97697312e
comparison
equal deleted inserted replaced
458:9a4bffdf37c3 459:9d3bd7304050
11 from django.shortcuts import render_to_response 11 from django.shortcuts import render_to_response
12 from django.template import RequestContext 12 from django.template import RequestContext
13 from django.views.decorators.http import require_POST 13 from django.views.decorators.http import require_POST
14 14
15 from forums.models import Topic 15 from forums.models import Topic
16 import forums.permissions as perms
16 from core.functions import send_mail 17 from core.functions import send_mail
17 from core.paginator import DiggPaginator 18 from core.paginator import DiggPaginator
18 19
19 20
20 def notify_topic_subscribers(post): 21 def notify_topic_subscribers(post):
48 @login_required 49 @login_required
49 @require_POST 50 @require_POST
50 def subscribe_topic(request, topic_id): 51 def subscribe_topic(request, topic_id):
51 """Subscribe the user to the requested topic.""" 52 """Subscribe the user to the requested topic."""
52 topic = get_object_or_404(Topic.objects.select_related(), id=topic_id) 53 topic = get_object_or_404(Topic.objects.select_related(), id=topic_id)
53 if topic.forum.category.can_access(request.user): 54 if perms.can_access(topic.forum.category, request.user):
54 topic.subscribers.add(request.user) 55 topic.subscribers.add(request.user)
55 return HttpResponseRedirect( 56 return HttpResponseRedirect(
56 reverse("forums-subscription_status", args=[topic.id])) 57 reverse("forums-subscription_status", args=[topic.id]))
57 raise Http404 58 raise Http404
58 59