def answer_question(request, question): """Record answer to question, only tutors can answer question Then publish the event """ if request.method == 'POST': form = AnswerQuestionForm(data=request.POST) message = {"success": True} if form.is_valid(): question = form.save(question) channel = "classroom_{0}".format(question.classroom.pk) message = { "type": "answer_question", "question": { "pk": question.pk, "subject": question.subject, "content": question.content, "student": question.student.username, "vote_count": question.vote_count(), "answer": question.answer, } } publish(channel, message) else: message = {"error": form.errors} return HttpResponseBadRequest(message) return HttpResponse(json.dumps(message)) return HttpResponseNotFound("Need to post")
def question_answer(request, id): manager = QuestionManager.get_manager(request.user) if not manager: return HttpResponse(u'Вы не можете обрабатывать вопросы') question = get_object_or_404(Question, id=id) if question.is_ready(): return HttpResponse(u'Ответ на вопрос уже дан.') if request.method == 'POST': form = AnswerQuestionForm(request.POST, instance=question) if form.is_valid(): question = form.save(commit=False) if question.is_new(): question.take_to_process(manager, commit=False) question.close_process() if question.email: domain = settings.SITE_DOMAIN from_mail = settings.DEFAULT_FROM_EMAIL send_mail(u"Спроси библиотекаря", u'Ваш вопрос был обработан. Вы можете посмотреть ответ по адресу http://%s%s' % (domain, urlresolvers.reverse('ask_librarian:frontend:detail', args=(question.id,))), from_mail, [question.email], # fail_silently=True ) return redirect('ask_librarian:administration:question_detail', id=id) else: form = AnswerQuestionForm(instance=question) return render(request, 'ask_librarian/administration/question_answer.html', { 'question': question, 'form': form })
def question_answer(request, id): manager = QuestionManager.get_manager(request.user) if not manager: return HttpResponse(u'Вы не можете обрабатывать вопросы') question = get_object_or_404(Question, id=id) if question.is_ready(): return HttpResponse(u'Ответ на вопрос уже дан.') if request.method == 'POST': form = AnswerQuestionForm(request.POST, instance=question) if form.is_valid(): question = form.save(commit=False) if question.is_new(): question.take_to_process(manager, commit=False) question.close_process() return redirect('ask_librarian:administration:question_detail', id=id) else: form = AnswerQuestionForm(instance=question) return render(request, 'ask_librarian/administration/question_answer.html', { 'question': question, 'form': form })
def question_edit(request, id): question = get_object_or_404(Question, id=id) if (question.manager and not question.manager.user_id == request.user.id) and not request.user.is_superuser: return HttpResponse(u'Вы не можете обрабатывать вопросы') if request.method == 'POST': form = AnswerQuestionForm(request.POST, instance=question) if form.is_valid(): form.save() return redirect('ask_librarian:administration:question_detail', id=id) else: form = AnswerQuestionForm(instance=question) return render(request, 'ask_librarian/administration/question_edit.html', { 'question': question, 'form': form })