def question_detail(request, pk): questions = Question.objects.all() question = get_object_or_404(questions, pk=pk) responses = question.responses.order_by("-score", "created", "id") is_me = question.user == request.user if request.method == "POST": add_response_form = AddResponseForm(request.POST) if add_response_form.is_valid(): response = add_response_form.save(commit=False) response.question = question response.user = request.user response.save() return HttpResponseRedirect(response.get_absolute_url()) else: if not is_me or request.user.is_staff: add_response_form = AddResponseForm() else: add_response_form = None ctx = { "can_mark_accepted": workflow.can_mark_accepted(request.user, question), "question": question, "responses": responses, "add_response_form": add_response_form, } return render(request, "aiteo/question_detail.html", ctx)
def question_detail(request, question_id, **kwargs): group, bridge = group_and_bridge(kwargs) questions = Question.objects.all() if group: questions = group.content_objects(questions) else: questions = questions.filter(group_content_type=None) question = get_object_or_404(questions, pk=question_id) responses = question.responses.order_by("-score", "created", "id") if question.user == request.user: is_me = True else: is_me = False if request.method == "POST": add_response_form = AddResponseForm(request.POST) if add_response_form.is_valid(): response = add_response_form.save(commit=False) response.question = question response.user = request.user response.save() return HttpResponseRedirect(response.get_absolute_url()) else: if not is_me or request.user.is_staff: add_response_form = AddResponseForm() else: add_response_form = None ctx = group_context(group, bridge) ctx.update({ "group": group, "can_mark_accepted": workflow.can_mark_accepted(request.user, question), "question": question, "responses": responses, "add_response_form": add_response_form, }) ctx = RequestContext(request, ctx) return render_to_response("aiteo/question_detail.html", ctx)