def api_add_post(request, opening_post_id): """ Adds a post and return the JSON response for it """ opening_post = get_object_or_404(Post, id=opening_post_id) status = STATUS_OK errors = [] if request.method == "POST": form = PostForm(request.POST, request.FILES, error_class=PlainErrorList) form.session = request.session # if form.need_to_ban: # # Ban user because he is suspected to be a bot # _ban_current_user(request) # status = STATUS_ERROR if form.is_valid(): ThreadView().new_post(request, form, opening_post, html_response=False) else: status = STATUS_ERROR errors = form.as_json_errors() response = {"status": status, "errors": errors} return HttpResponse(content=json.dumps(response))
def post(self, request, post_id, mode=MODE_NORMAL): opening_post = get_object_or_404(Post, id=post_id) # If this is not OP, don't show it as it is if not opening_post.is_opening(): raise Http404 if not opening_post.get_thread().archived: form = PostForm(request.POST, request.FILES, error_class=PlainErrorList) form.session = request.session if form.is_valid(): return self.new_post(request, form, opening_post) if form.need_to_ban: # Ban user because he is suspected to be a bot self._ban_current_user(request) return self.get(request, post_id, mode, form)