def get(self, request, question_slug, question_id): prefetch = ( 'author', 'author__profile', 'author__profile__occupation', ) related = ('author') question = business.get_question(question_id, prefetch=prefetch, related=related) if not question or (question and question.slug != question_slug): raise Http404(_("Question is not exists!")) answers = business.get_all_answers_by_question(question, prefetch=prefetch, related=related) form_answer = EditAnswerForm() context = { 'question': question, 'answers': answers, 'form_answer': form_answer } context.update(self.get_context(request, question)) return render(request, self.template_name, context)
def post(self, request): question_id = request.POST.get('question_id', None) question = business.get_question(question_id) if not question: raise Http404(_("Question is not exists!")) if not (question.author_id == request.user.id) and not request.user.has_perm( 'question.change_other_questions'): return HttpResponseForbidden() form = self.form(data=request.POST, instance=question, user=request.user) if form.process(): messages.add_message(request, messages.SUCCESS, _("Question updated successfully!"), 'question-edit') return redirect(reverse('question:edit', args=[question.id])) else: messages.add_message(request, messages.ERROR, 'Erro ao carregar question', 'question-edit') return render(request, 'question/edit_question.html', { 'form': form, 'question': question })
def post(self, request): question = business.get_question(request.POST["question_id"]) if not question: raise Http404(_("Question not found")) self.form = CommentReplyForm(request.POST, request.user) return super(CommentReplayView, self).do_process(request)
def get(self, request, question_id): question = business.get_question(question_id) if not question: raise Http404(_("Question is not exists!")) if not (question.author_id == request.user.id) and not request.user.has_perm( 'question.change_other_questions'): return HttpResponseForbidden() form = self.form(user=request.user, instance=question) context = {'form': form, 'question': question} return render(request, 'question/edit_question.html', self.prepare_context(request, context))
def post(self, request, question_id): if question_id != request.POST.get('item-id'): context = { 'status': 401, 'errors': { '__all__': [_('Question not Found.')] } } return self.return_error(request, context) question = Business.get_question(question_id) # Fail if is not owner if not question.check_is_owner(request.user): context = { 'status': 403, 'errors': { '__all__': [self.msg_not_found] } } return self.return_error(request, context) if not question.id: context = { 'status': 401, 'errors': { '__all__': [self.msg_not_found] } } return self.return_error(request, context) if question.deleted: context = { 'status': 400, 'errors': { '__all__': [_("This question has been deleted")] } } return self.return_error(request, context) if Business.delete_question(question): return self.return_error(request, {'status': 400}) context = {'question': question} return self.return_success(request, context)