def forum_thread(request, thread_id): thread = get_object_or_404(ForumThread, id=thread_id) if request.method == "POST" and request.user.is_authenticated: content = request.POST.get("content") subscribe = {"true": True, "false": False, False: False}.get(request.POST.get("subscribe", False), True) reply = ForumReply(thread=thread, author=request.user, content=content) reply.save() # subscribe the poster to the thread if requested (default value is True) if subscribe: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect(reverse("agora_thread", args=[thread_id])) order_type = request.GET.get("order_type", "asc") posts = ForumThread.objects.posts(thread, reverse=(order_type == "desc")) thread.inc_views() return render_to_response("agora/thread.html", { "thread": thread, "posts": posts, "order_type": order_type, "subscribed": thread.subscribed(request.user, "email"), }, context_instance=RequestContext(request))
def restore(cls, in_): data = json.load(open(in_)) forum = Forum(**dict( id=data["self"]["id"], title=data["self"]["title"], description=data["self"]["description"], parent_id=data["self"]["parent"], category_id=data["self"]["category"], last_modified=data["self"]["last_modified"], view_count=data["self"]["view_count"], post_count=data["self"]["post_count"] )) forum._importing = True forum.save() for thread_data in data["threads"]: thread = ForumThread(**dict( id=thread_data["id"], author_id=thread_data["author"], content=thread_data["content"], created=thread_data["created"], forum_id=thread_data["forum"], title=thread_data["title"], last_modified=thread_data["last_modified"], view_count=thread_data["view_count"], reply_count=thread_data["reply_count"], subscriber_count=thread_data["subscriber_count"] )) thread._importing = True thread.save() for reply_data in thread_data["replies"]: reply = ForumReply(**dict( id=reply_data["id"], author_id=reply_data["author"], content=reply_data["content"], created=reply_data["created"], thread_id=reply_data["thread"], )) reply._importing = True reply.save() for subscriber_data in thread_data["subscriptions"]: ThreadSubscription(**dict( id=subscriber_data["id"], user_id=subscriber_data["user"], thread_id=subscriber_data["thread"], kind=subscriber_data["kind"], )).save() thread.last_reply_id = thread_data["last_reply"] thread.save() forum.last_thread_id = data["self"]["last_thread"] forum.save()
def restore(cls, in_): data = json.load(open(in_)) forum = Forum(**dict(id=data["self"]["id"], title=data["self"]["title"], description=data["self"]["description"], parent_id=data["self"]["parent"], category_id=data["self"]["category"], last_modified=data["self"]["last_modified"], view_count=data["self"]["view_count"], post_count=data["self"]["post_count"])) forum._importing = True forum.save() for thread_data in data["threads"]: thread = ForumThread( **dict(id=thread_data["id"], author_id=thread_data["author"], content=thread_data["content"], created=thread_data["created"], forum_id=thread_data["forum"], title=thread_data["title"], last_modified=thread_data["last_modified"], view_count=thread_data["view_count"], reply_count=thread_data["reply_count"], subscriber_count=thread_data["subscriber_count"])) thread._importing = True thread.save() for reply_data in thread_data["replies"]: reply = ForumReply(**dict( id=reply_data["id"], author_id=reply_data["author"], content=reply_data["content"], created=reply_data["created"], thread_id=reply_data["thread"], )) reply._importing = True reply.save() for subscriber_data in thread_data["subscriptions"]: ThreadSubscription(**dict( id=subscriber_data["id"], user_id=subscriber_data["user"], thread_id=subscriber_data["thread"], kind=subscriber_data["kind"], )).save() thread.last_reply_id = thread_data["last_reply"] thread.save() forum.last_thread_id = data["self"]["last_thread"] forum.save()
def reply(request, thread_id): member = request.user.get_profile() thread = get_object_or_404(ForumThread, id=thread_id) quote = request.GET.get("quote") # thread id to quote if quote: quote_reply = ForumReply.objects.get(id=int(quote)) quote_content = "\"%s\"" % quote_reply.content else: quote_content = "" if request.method == "POST": content = request.POST.get("content") subscribe = {"true": True, "false": False, False: False}.get(request.POST.get("subscribe", False), True) reply = ForumReply(thread=thread, author=request.user, content=content) reply.save() # subscribe the poster to the thread if requested (default value is True) if subscribe: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect(reverse("agora_thread", args=[thread_id])) first_reply = not ForumReply.objects.filter(thread=thread, author=request.user).exists() return render_to_response("agora/reply.html", { "member": member, "thread_id": thread_id, "quote_content": quote_content, "subscribed": thread.subscribed(request.user, "email"), "first_reply": first_reply, }, context_instance=RequestContext(request))