Skip to content

Commit

Permalink
added forum closed and some other tweaks to permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner committed Dec 17, 2011
1 parent ecfa0b2 commit 44b3e0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions agora/models.py
Expand Up @@ -46,6 +46,7 @@ class Forum(models.Model):

title = models.CharField(max_length=100)
description = models.TextField()
closed = models.DateTimeField(null=True, blank=True)

# must only have one of these (or neither):
parent = models.ForeignKey("self",
Expand Down
21 changes: 17 additions & 4 deletions agora/views.py
Expand Up @@ -65,7 +65,10 @@ def forum(request, forum_id):
forum = get_object_or_404(Forum, id=forum_id)
threads = forum.threads.order_by("-sticky", "-last_modified")

can_create_thread = request.user.has_perm("agora.add_forumthread", obj=forum)
can_create_thread = all([
request.user.has_perm("agora.add_forumthread", obj=forum),
not forum.closed,
])

return render_to_response("agora/forum.html", {
"forum": forum,
Expand All @@ -75,11 +78,16 @@ def forum(request, forum_id):


def forum_thread(request, thread_id):
thread = get_object_or_404(ForumThread, id=thread_id)
qs = ForumThread.objects.select_related("forum")
thread = get_object_or_404(qs, id=thread_id)

can_create_reply = request.user.has_perm("agora.add_forumreply", obj=thread)
can_create_reply = all([
request.user.has_perm("agora.add_forumreply", obj=thread),
not thread.closed,
not thread.forum.closed,
])

if request.user.is_authenticated() and not thread.closed and can_create_reply:
if can_create_reply:
if request.method == "POST":
reply_form = ReplyForm(request.POST)

Expand Down Expand Up @@ -125,6 +133,10 @@ def post_create(request, forum_id):
member = request.user.get_profile()
forum = get_object_or_404(Forum, id=forum_id)

if forum.closed:
messages.error(request, "This forum is closed.")
return HttpResponseRedirect(reverse("agora_forum", args=[forum.id]))

can_create_thread = request.user.has_perm("agora.add_forumthread", obj=forum)

if not can_create_thread:
Expand Down Expand Up @@ -167,6 +179,7 @@ def reply_create(request, thread_id):

if thread.closed:
messages.error(request, "This thread is closed.")
return HttpResponseRedirect(reverse("agora_thread", args=[thread.id]))

can_create_reply = request.user.has_perm("agora.add_forumreply", obj=thread)

Expand Down

0 comments on commit 44b3e0d

Please sign in to comment.