def question_list(request, course_slug, **kwargs): course = get_object_or_404(Course, slug=course_slug) group, bridge = group_and_bridge(kwargs) questions = Question.objects.filter(course=course) questions = questions.order_by("-score", "created", "id") if group: questions = group.content_objects(questions) else: questions = questions.filter(group_content_type=None) is_enrolled = course.students.filter(id=request.user.id).exists() is_teacher = is_teacher_test(request.user, course) ctx = group_context(group, bridge) ctx.update({ "course": course, "show_material": True, "is_enrolled": is_enrolled, "is_teacher": is_teacher, "group": group, "questions": questions, }) ctx = RequestContext(request, ctx) return render_to_response("discussion/question_list.html", ctx)
def question_create(request, course_slug, **kwargs): course = get_object_or_404(Course, slug=course_slug) group, bridge = group_and_bridge(kwargs) if request.method == "POST": form = AskQuestionForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.user = request.user question.course = course question.save() return HttpResponseRedirect(question.get_absolute_url()) else: form = AskQuestionForm() is_enrolled = course.students.filter(id=request.user.id).exists() is_teacher = is_teacher_test(request.user, course) ctx = group_context(group, bridge) ctx.update({ "course": course, "show_material": True, "is_enrolled": is_enrolled, "is_teacher": is_teacher, "group": group, "form": form, }) ctx = RequestContext(request, ctx) return render_to_response("discussion/question_create.html", ctx)
def question_detail(request, course_slug, question_id, **kwargs): course = get_object_or_404(Course, slug=course_slug) 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: add_response_form = AddResponseForm() # if not is_me or request.user.is_staff: # add_response_form = AddResponseForm() # else: # add_response_form = None is_enrolled = course.students.filter(id=request.user.id).exists() is_teacher = is_teacher_test(request.user, course) can_mark_accepted = workflow.can_mark_accepted(request.user, question) ctx = group_context(group, bridge) ctx.update({ "course": course, "show_material": True, "is_enrolled": is_enrolled, "is_teacher": is_teacher, "group": group, "can_mark_accepted": can_mark_accepted, "question": question, "responses": responses, "add_response_form": add_response_form, }) ctx = RequestContext(request, ctx) return render_to_response("discussion/question_detail.html", ctx)
def mark_accepted(request, course_slug, question_id, response_id, **kwargs): course = get_object_or_404(Course, slug=course_slug) # if request.method != "POST": # return HttpResponseNotAllowed(["POST"]) 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, course=course) if not workflow.can_mark_accepted(request.user, question): msg = _("You are not allowed to mark this question accepted.") return HttpResponseForbidden(msg) response = question.responses.get(pk=response_id) response.accept() return HttpResponseRedirect(response.question.get_absolute_url())