def topic_reply(request, topic_id): topic = get_object_or_404(Topic, id=topic_id) post = Post(topic=topic, user=request.user) if request.POST: form = ReplyForm(request.POST, instance=post) if form.is_valid(): form.save() topic.last_post_at = post.created_at topic.last_post_by_user = request.user topic.reply_count = topic.posts.count() - 1 topic.save() return redirect(topic.get_absolute_url() + ('#post-%d' % post.id)) else: # the only possible error is leaving the box totally empty. # Redirect back to topic page in that case return redirect(topic.get_absolute_url()) else: form = ReplyForm(instance=post) return render(request, 'forums/add_reply.html', { 'menu_section': 'forums', 'topic': topic, 'form': form, })
def reply(request, forum_slug, thread_id): """Reply to a thread.""" forum = get_object_or_404(Forum, slug=forum_slug) user = request.user if not forum.allows_posting_by(user): if forum.allows_viewing_by(user): raise PermissionDenied else: raise Http404 form = ReplyForm(request.POST) reply_preview = None if form.is_valid(): thread = get_object_or_404(Thread, pk=thread_id, forum=forum) if not thread.is_locked: reply_ = form.save(commit=False) reply_.thread = thread reply_.author = request.user if 'preview' in request.POST: reply_preview = reply_ else: reply_.save() # Send notifications to thread/forum watchers. NewPostEvent(reply_).fire(exclude=reply_.author) return HttpResponseRedirect(reply_.get_absolute_url()) return posts(request, forum_slug, thread_id, form, reply_preview)
def reply_to_parent(request, parent_id): """ Creates a form for sending replies Also creates a reply on POST Relies on jQuery's html-handling """ ctx = {} template_name = 'forums/api/reply_to_parent.html' reply_form = ReplyForm() ctx['reply_form'] = reply_form ctx['parent_id'] = parent_id parent = Reply.objects.get(id=base36_to_int(parent_id)) topic = parent.topic if request.method == 'POST': reply_form = ReplyForm(request.POST) reply_form.topic = topic reply_form.author = request.user if reply_form.is_valid: reply = reply_form.save(commit=False) reply.author = request.user reply.topic = topic reply.parent = parent reply.status = 'posted' reply.entry = reply.draft reply.save() messages.warning(request, "Thank you for your reply. It has been sent for moderation") return redirect(topic.get_absolute_url()) return render(request, template_name, ctx)
def reply_to_topic(request, topic_id): """ A direct reply to a topic """ ctx = {} template_name = 'forums/api/reply_form.html' reply_form = ReplyForm() ctx['reply_form'] = reply_form ctx['topic_id'] = topic_id topic = Topic.objects.get(id=base36_to_int(topic_id)) if request.method == 'POST': reply_form = ReplyForm(request.POST) reply_form.topic = topic reply_form.author = request.user if reply_form.is_valid: reply = reply_form.save(commit=False) reply.author = request.user reply.topic = topic reply.save() messages.warning(request, "Thank you for your reply. It has been sent for moderation") return redirect(topic.get_absolute_url()) # we might have to use a JS return # response = HttpResponse() # response.type = 'text/javascript' # response.write('Success!') # return response return render(request, template_name, ctx)
def reply_create(request, thread_id): member = request.user.profile thread = get_object_or_404(ForumThread, id=thread_id) if thread.closed: messages.error(request, "This thread is closed.") return HttpResponseRedirect(reverse("forums_thread", args=[thread.id])) can_create_reply = request.user.has_perm("forums.add_forumreply", obj=thread) if not can_create_reply: messages.error(request, "You do not have permission to reply to this thread.") return HttpResponseRedirect(reverse("forums_thread", args=[thread.id])) if request.method == "POST": form = ReplyForm(request.POST) if form.is_valid(): reply = form.save(commit=False) reply.thread = thread reply.author = request.user reply.save() # subscribe the poster to the thread if requested (default value is True) if form.cleaned_data["subscribe"]: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect( reverse("forums_thread", args=[thread_id])) else: quote = request.GET.get("quote") # thread id to quote initial = {} if quote: quote_reply = ForumReply.objects.get(id=int(quote)) initial["content"] = "\"%s\"" % quote_reply.content form = ReplyForm(initial=initial) first_reply = not ForumReply.objects.filter(thread=thread, author=request.user).exists() return render_to_response( "forums/reply_create.html", { "form": form, "member": member, "thread": thread, "subscribed": thread.subscribed(request.user, "email"), "first_reply": first_reply, }, context_instance=RequestContext(request))
def reply_create(request, thread_id): member = request.user thread = get_object_or_404(ForumThread, id=thread_id) if thread.closed: messages.error(request, "This thread is closed.") return HttpResponseRedirect(reverse("forums_thread", args=[thread.id])) can_create_reply = request.user.has_perm("forums.add_forumreply", obj=thread) if not can_create_reply: messages.error(request, "You do not have permission to reply to this thread.") return HttpResponseRedirect(reverse("forums_thread", args=[thread.id])) if request.method == "POST": form = ReplyForm(request.POST) if form.is_valid(): reply = form.save(commit=False) reply.thread = thread reply.author = request.user reply.save() # subscribe the poster to the thread if requested (default value is True) if form.cleaned_data["subscribe"]: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect(reverse("forums_thread", args=[thread_id])) else: quote = request.GET.get("quote") # thread id to quote initial = {} if quote: quote_reply = ForumReply.objects.get(id=int(quote)) initial["content"] = "\"%s\"" % quote_reply.content form = ReplyForm(initial=initial) first_reply = not ForumReply.objects.filter(thread=thread, author=request.user).exists() return render_to_response("forums/reply_create.html", { "form": form, "member": member, "thread": thread, "subscribed": thread.subscribed(request.user, "email"), "first_reply": first_reply, }, context_instance=RequestContext(request))
def forum_thread(request, thread_id): qs = ForumThread.objects.select_related("forum") thread = get_object_or_404(qs, id=thread_id) can_create_reply = all([ request.user.has_perm("forums.add_forumreply", obj=thread), not thread.closed, not thread.forum.closed, ]) if can_create_reply: if request.method == "POST": reply_form = ReplyForm(request.POST) if reply_form.is_valid(): reply = reply_form.save(commit=False) reply.thread = thread reply.author = request.user reply.save() # subscribe the poster to the thread if requested (default value is True) if reply_form.cleaned_data["subscribe"]: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect( reverse("forums_thread", args=[thread.id])) else: reply_form = ReplyForm() else: reply_form = None order_type = request.GET.get("order_type", "asc") posts = ForumThread.objects.posts(thread, reverse=(order_type == "desc")) thread.inc_views() return render_to_response( "forums/thread.html", { "thread": thread, "posts": posts, "order_type": order_type, "subscribed": thread.subscribed(request.user, "email"), "reply_form": reply_form, "can_create_reply": can_create_reply, }, context_instance=RequestContext(request))
def forum_thread(request, thread_id): qs = ForumThread.objects.select_related("forum") thread = get_object_or_404(qs, id=thread_id) can_create_reply = all([ request.user.has_perm("forums.add_forumreply", obj=thread), not thread.closed, not thread.forum.closed, ]) if can_create_reply: if request.method == "POST": reply_form = ReplyForm(request.POST) if reply_form.is_valid(): reply = reply_form.save(commit=False) reply.thread = thread reply.author = request.user reply.save() # subscribe the poster to the thread if requested (default value is True) if reply_form.cleaned_data["subscribe"]: thread.subscribe(reply.author, "email") # all users are automatically subscribed to onsite thread.subscribe(reply.author, "onsite") return HttpResponseRedirect(reverse("forums_thread", args=[thread.id])) else: reply_form = ReplyForm() else: reply_form = None order_type = request.GET.get("order_type", "asc") posts = ForumThread.objects.posts(thread, reverse=(order_type == "desc")) thread.inc_views() return render_to_response("forums/thread.html", { "thread": thread, "posts": posts, "order_type": order_type, "subscribed": thread.subscribed(request.user, "email"), "reply_form": reply_form, "can_create_reply": can_create_reply, }, context_instance=RequestContext(request))
def reply(request, forum_slug, thread_id): """Reply to a thread.""" forum = get_object_or_404(Forum, slug=forum_slug) user = request.user if not forum.allows_posting_by(user): if forum.allows_viewing_by(user): raise PermissionDenied else: raise Http404 form = ReplyForm(request.POST) post_preview = None if form.is_valid(): thread = get_object_or_404(Thread, pk=thread_id, forum=forum) if not thread.is_locked: reply_ = form.save(commit=False) reply_.thread = thread reply_.author = request.user if 'preview' in request.POST: post_preview = reply_ post_preview.author_post_count = \ reply_.author.post_set.count() else: reply_.save() statsd.incr('forums.reply') # Subscribe the user to the thread. if Setting.get_for_user(request.user, 'forums_watch_after_reply'): NewPostEvent.notify(request.user, thread) # Send notifications to thread/forum watchers. NewPostEvent(reply_).fire(exclude=reply_.author) return HttpResponseRedirect(thread.get_last_post_url()) return posts(request, forum_slug, thread_id, form, post_preview, is_reply=True)
def reply_to_thread(request, pk): thread = get_object_or_404(Thread, id=pk) reply_form = ReplyForm(data=request.POST) """Reply to a thread.""" if request.method == 'POST': if reply_form.is_valid(): r = reply_form.save(commit=False) r.thread_id = thread.pk r.creator_id = request.user.pk r.save() else: print(reply_form.errors) return HttpResponseRedirect(reverse("forums.views.show_thread", args=[thread.pk]) + "?page=last")