Mercurial > public > sg101
comparison gpp/forums/views/favorites.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 | b2b37cdd020a |
children |
comparison
equal
deleted
inserted
replaced
458:9a4bffdf37c3 | 459:9d3bd7304050 |
---|---|
11 from django.http import HttpResponseForbidden | 11 from django.http import HttpResponseForbidden |
12 from django.http import Http404 | 12 from django.http import Http404 |
13 | 13 |
14 from core.paginator import DiggPaginator | 14 from core.paginator import DiggPaginator |
15 from forums.models import Topic | 15 from forums.models import Topic |
16 import forums.permissions as perms | |
16 | 17 |
17 | 18 |
18 @login_required | 19 @login_required |
19 @require_POST | 20 @require_POST |
20 def favorite_topic(request, topic_id): | 21 def favorite_topic(request, topic_id): |
21 """ | 22 """ |
22 This function handles the "favoriting" (bookmarking) of a forum topic by a | 23 This function handles the "favoriting" (bookmarking) of a forum topic by a |
23 user. | 24 user. |
24 """ | 25 """ |
25 topic = get_object_or_404(Topic.objects.select_related(), id=topic_id) | 26 topic = get_object_or_404(Topic.objects.select_related(), id=topic_id) |
26 if topic.forum.category.can_access(request.user): | 27 if perms.can_access(topic.forum.category, request.user): |
27 topic.bookmarkers.add(request.user) | 28 topic.bookmarkers.add(request.user) |
28 return HttpResponseRedirect( | 29 return HttpResponseRedirect( |
29 reverse("forums-favorites_status", args=[topic.id])) | 30 reverse("forums-favorites_status", args=[topic.id])) |
30 raise Http404 # TODO return HttpResponseForbidden instead | 31 return HttpResponseForbidden() |
31 | 32 |
32 | 33 |
33 @login_required | 34 @login_required |
34 def manage_favorites(request): | 35 def manage_favorites(request): |
35 """Display a user's favorite topics and allow them to be deleted.""" | 36 """Display a user's favorite topics and allow them to be deleted.""" |