Esempio n. 1
0
def get_questions_by_level(request, level, user):
    questions = Question.objects.filter(
        level=level, assigned_class=user.get_assigned_class())
    questions_serialized = list(
        map(lambda question: QuestionSerializer.serialize(question),
            questions))
    return ok({'questions': questions_serialized})
Esempio n. 2
0
def get_questions_by_tag(request, tag, user):
    questions = Question.objects.filter(
        tags__contains=[tag], assigned_class=user.get_assigned_class())
    questions_serialized = list(
        map(lambda question: QuestionSerializer.serialize(question),
            questions))
    return ok({'questions': questions_serialized})
Esempio n. 3
0
def put_question(request, questionId):
    question_fields_to_update = json.loads(request.body)
    question = Question.objects.get(pk=questionId)
    for field, value in get_validated_update_items(question_fields_to_update):
        setattr(question, field, value)
    if 'choices' in question_fields_to_update:
        update_question_choices(question_fields_to_update['choices'])
    question.save()
    return ok(QuestionSerializer.serialize(question))
Esempio n. 4
0
def get_single_question(request, questionId):
    question = Question.objects.get(pk=questionId)
    return ok(QuestionSerializer.serialize(question))
Esempio n. 5
0
def delete_question(request, questionId):
    question = Question.objects.get(pk=questionId)
    question_serialized = QuestionSerializer.serialize(question)
    question.delete()
    return ok(question_serialized)