Exemple #1
0
def get_question_structure(evalpk, parentpk):
    evaluation = get_object_or_404(Evaluation, pk=evalpk)
    parent = get_object_or_404(Question, pk=parentpk)
    root = Question.get_root_nodes().filter(evaluation=evaluation,
                                            stype="EVL")[0]
    questions = Question.get_annotated_list(root)
    return evaluation, parent, questions
Exemple #2
0
def create_question(request):
    """
    Endpoint: /users/create_user/
    Method: POST
    Allowed users: All user
    Response status code: 201 created
    Description: admin can create users of a
    """

    #  if not request.user.has_perm('users.add_user'):
    #     return Response({'error': 'can not create user'}, status=status.HTTP_403_FORBIDDEN)

    question_details = request.data

    que = Question(question=question_details['question'],
                   category=question_details['category'],
                   evaluation_id=question_details['evaluation_id'],
                   rating=question_details['rating'])
    que.save()

    return Response({'success': "user added successfully"},
                    status=status.HTTP_201_CREATED)
Exemple #3
0
def create_evaluation(request):
    """
    Endpoint: /users/create_user/
    Method: POST
    Allowed users: All user
    Response status code: 201 created
    Description: admin can create users of a
    """

    #  if not request.user.has_perm('users.add_user'):
    #     return Response({'error': 'can not create user'}, status=status.HTTP_403_FORBIDDEN)

    evaluation_details = request.data
    lecturer = User.objects.get(id=evaluation_details['lecturer_id'])
    student = User.objects.get(id=evaluation_details['student_id'])
    #unit = Unit.objects.get(id=evaluation_details['unit_id'])

    eval = Evaluation(
        lecturer_id=lecturer,
        student_id=student,
        #  unit_id=unit,
    )
    eval.save()
    eval_details = {}
    eval_details['evaluation_id'] = eval.id

    question_details = request.data['questions']
    for que_details in question_details:
        evaluation = Evaluation.objects.get(id=eval.id)
        que = Question(question=que_details['question'],
                       category=que_details['category'],
                       evaluation_id=evaluation,
                       rating=que_details['rating'])
        que.save()

    return Response({'success': "Evaluation successfully"},
                    status=status.HTTP_201_CREATED)
Exemple #4
0
def correction(request, evalpk, studentpk):
    """ Display and store the correction of an evaluation (single page)

    - get evaluation, evaluation questions
    - for each question, get points / evalitems
    -    for each point / evalitem, search details
    -       if no details, display a form for the teacher with answers
    -       if details, search for an answer using the questionform
    -           process answer, put point
    -           if process fail, display a form
    - if no form is given
    """

    ## DEBUG
    student = get_object_or_404(Student, pk=studentpk)
    evaluation = get_object_or_404(Evaluation, pk=evalpk)
    root = Question.get_root_nodes().filter(evaluation=evaluation,
                                            stype="EVL")[0]
    questions = Question.get_annotated_list(root)

    for question, _annotation in questions:

        # get evalitem
        for evalitem in question.evalitems.all():
            evdetails = evalitem.details.all()
            if evdetails is None:
                # display a form
                pass
            else:
                for evdetail in evalitem.details.all():
                    corr = evdetail.correction(student)
                    for cr in corr:
                        cr.save()

    return render(request, 'evaluation/correction/correction.html',
                  {'evaluation': evaluation, 'questions': questions})
Exemple #5
0
def evaluation_create(request):
    """ Create an evaluation and the root question associated """
    if request.method == "POST":
        form = EvaluationForm(request.POST)
        if form.is_valid():
            evaluation = form.save()
            question = Question.add_root(stype="EVL",
                                         evaluation=evaluation,
                                         structure=True,
                                         title=evaluation.title,
                                         text=evaluation.description,
                                         ttype='NN')
            return HttpResponseRedirect(
                reverse('question-details', kwargs={
                    'evalpk': evaluation.pk,
                    'parentpk': question.pk}))
    else:
        form = EvaluationForm()
    return render(request, 'evaluation/evaluation_form.html',
                  {'form': form})