Ejemplo n.º 1
0
def __update_question_method(request, question_id, context):
    if request.method == 'POST':
        try:
            question = __set_update_question_attribute(request)
            service_controller.question_management_service().edit(question_id, question)
            context['saved'] = 'success'
        except Exception as e:
            print('This Question Creation could not be completed')
            raise e
Ejemplo n.º 2
0
def tutor_questions(request):
    if request.method == 'GET':
        if request.user.tutor_set.exists():
            user_id = request.user.id
            tutor = service_controller.tutor_management_service().details(user_id)
            tutor_id = tutor.id
            questions = service_controller.question_management_service().list_question_for_tutor(tutor_id)
            serializer = TutorQuestionsSerializer(questions, many=True)
            json_data = serializer.data
            return Response(json_data)

        elif request.user.adminuser_set.exists():
            questions = service_controller.question_management_service().list()
            serializer = QuestionSerializer(questions, many=True)
            json_data = serializer.data
            return Response(json_data)
Ejemplo n.º 3
0
def __set_grading_attribute_request(request: HttpRequest, sitting_id):
    grade_sitting_dto = GradeSittingDto()
    grade_sitting_dto.sitting_id = sitting_id
    sitting = service_controller.sitting_management_service().details(
        sitting_id)

    question = sitting.question_list
    questions: list = question.strip('][').split(', ')

    answer = sitting.answer_list
    answers: list = answer.strip('][').split(', ')

    user_answer = sitting.user_answer
    user_answers: list = user_answer.strip('][').split(', ')

    user_score = []

    for qns in questions:
        for ans in answers:
            answers.remove(ans)
            for user_ans in user_answers:
                user_answers.remove(user_ans)
                questions_object = service_controller.question_management_service(
                ).details(qns)
                qns_grade = questions_object.assigned_mark
                if ans == user_ans:
                    user_score.append(qns_grade)
                else:
                    user_score.append(0)
                break
            break

    total_score = sum(user_score)

    assessment_id = sitting.assessment_id
    assessment = service_controller.assessment_management_service().details(
        assessment_id)

    if (sitting.date_submitted > assessment.date_due and sitting.time_submitted > assessment.time_due) or \
            (sitting.date_submitted > assessment.date_due and sitting.time_submitted <= assessment.time_due) or \
            (sitting.date_submitted == assessment.date_due and sitting.time_submitted > assessment.time_due):
        late_submission = 1
    else:
        late_submission = 0

    grade_sitting_dto.late_submission = late_submission

    if total_score >= assessment.pass_mark:
        failed = 0
    else:
        failed = 1

    grade_sitting_dto.failed = failed
    grade_sitting_dto.user_grade = total_score

    return grade_sitting_dto
Ejemplo n.º 4
0
def new_sitting(request, assessment_id):
    if request.user.has_perm('lms_app.add_sitting'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username

        user_id = request.user.id
        student_id = service_controller.student_management_service().details(
            user_id=user_id).id
        assessment = service_controller.assessment_management_service(
        ).details(assessment_id)
        questions = service_controller.question_management_service(
        ).list_for_assessment(assessment_id)
        sitting_question_list = []
        sitting_answer_list = []

        i = 1
        list_qns = []

        for question in questions:
            if assessment_id == question.assessment_id:
                sitting_question_list.append(question.id)
                list_qns.append(i)
                sitting_answer_list.append(question.answer)
                i = i + 1

        question_count = len(questions)
        paginator = Paginator(questions, 1)
        page_number = request.GET.get('page')
        page_obj = paginator.get_page(page_number)

        context = {
            'username': username,
            'assessment': assessment,
            'assessment_id': assessment_id,
            'question': questions,
            'sitting_question_list': sitting_question_list,
            'l_as_list': l_as_list,
            'question_count': question_count,
            'list_qns': list_qns,
            'questions': page_obj,
            'qns_page': page_number,
        }

        sitting = __new_sitting_method(request, sitting_answer_list,
                                       sitting_question_list, student_id,
                                       assessment_id, context)
        if request.method == 'POST':
            sitting_id = sitting.id
            return redirect('grade_test', sitting_id)
        return render(request, 'api_question.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 5
0
def delete_question(request, question_id):
    if request.user.has_perm('lms_app.delete_question'):
        try:
            question = service_controller.question_management_service().details(question_id)
            qns_score = question.assigned_mark
            assessment = Assessment.objects.get(id=question.assessment_id)
            new_score = assessment.total_score - qns_score
            assessment.total_score = int(new_score)
            service_controller.question_management_service().delete(question_id)
            assessment.save()
            return redirect('tutor_details')
        except Question.DoesNotExist as e:
            print('This question does not exist!')
            raise e
    else:
        context={
            'message': 'You are not authorised'
        }
        return render(request, 'error_message.html', context)
Ejemplo n.º 6
0
def tutor_details_for_admin(request, tutor_id):
    if request.user.has_perm('lms_app.view_tutor'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username
        tutor_ = Tutor.objects.get(id=tutor_id)
        tutor_id = tutor_.id

        user_id = tutor_.user.id
        tutor = service_controller.tutor_management_service().details(user_id)
        appointments = service_controller.appointment_management_service(
        ).list_appoint_for_tutor(tutor_id)
        appointment_len = len(appointments)
        assessments = service_controller.assessment_management_service(
        ).list_assessment_for_tutor(tutor_id)
        assessment_len = len(assessments)
        questions = service_controller.question_management_service(
        ).list_question_for_tutor(tutor_id)
        question_len = len(questions)

        sittings = service_controller.sitting_management_service().list()
        sitting_list = []

        for sitting in sittings:
            for assessment in assessments:
                if assessment.id == sitting.assessment_id:
                    sitting_list.append(sitting)

        sitting_len = len(sitting_list)

        context = {
            'tutor': tutor,
            'appointments': appointments,
            'assessments': assessments,
            'questions': questions,
            'sitting_list': sitting_list,
            'appointment_len': appointment_len,
            'assessment_len': assessment_len,
            'question_len': question_len,
            'sitting_len': sitting_len,
            'username': username,
            'l_as_list': l_as_list,
        }
        return render(request, 'tutor/tutor_profile.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 7
0
def question_details(request, question_id):
    if request.user.has_perm('lms_app.view_question'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username

        question = service_controller.question_management_service().details(question_id)

        context = {
            'username': username,
            'question': question,
            'l_as_list': l_as_list,
        }
        return render(request, 'question/get_question.html', context)
    else:
        context={
            'message': 'You are not authorised'
        }
        return render(request, 'error_message.html', context)
Ejemplo n.º 8
0
def list_questions(request):
    if request.user.has_perm('lms_app.view_question'):
        l_as_list = []
        list_all = ['all']
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username

        questions = service_controller.question_management_service().list()
        context = {
            'questions': questions,
            'username': username,
            'l_as_list': l_as_list,
            'list_all': list_all,
        }
        return render(request, 'question/list_questions.html', context)
    else:
        context = {
            'message': 'You are not authorised'
        }
        return render(request, 'error_message.html', context)
Ejemplo n.º 9
0
def update_question(request, question_id):
    if request.user.has_perm('lms_app.change_question'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username

        question = service_controller.question_management_service().details(question_id)

        context = {
            'question': question,
            'username': username,
            'l_as_list': l_as_list,
        }
        if request.method == 'POST':
            __update_question_method(request, question_id, context)
            return redirect('question_details', question_id)
        return render(request, 'question/edit_question.html', context)
    else:
        context={
            'message': 'You are not authorised'
        }
        return render(request, 'error_message.html', context)
Ejemplo n.º 10
0
def sitting_details(request, sitting_id):
    if request.user.has_perm('lms_app.view_sitting'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username

        sitting = service_controller.sitting_management_service().details(
            sitting_id)
        user_grade = service_controller.grading_management_service().details(
            sitting_id)
        assessment_id = sitting.assessment_id
        assessment = service_controller.assessment_management_service(
        ).details(assessment_id)
        questions = service_controller.question_management_service(
        ).list_for_assessment(assessment_id)

        question = sitting.question_list
        question_list: list = question.strip('][').split(', ')

        answer = sitting.answer_list
        answers: list = answer.strip('][').split(', ')

        user_answer = sitting.user_answer
        user_answers: list = user_answer.strip('][').split(', ')

        user_choice = dict(zip(question_list, user_answers))
        set_choice = dict(zip(question_list, answers))

        comments = service_controller.comment_management_service().list(
            assessment_id)
        comment_len = len(comments)

        i = 1
        list_qns = []
        for question in questions:
            if assessment_id == question.assessment_id:
                list_qns.append(i)
                i = i + 1

        paginator = Paginator(questions, 1)
        page_number = request.GET.get('page')
        page_obj = paginator.get_page(page_number)

        context = {
            'username': username,
            'sitting': sitting,
            'user_grade': user_grade,
            'assessment': assessment,
            'question': questions,
            'questions': page_obj,
            'user_choice': user_choice,
            'set_choice': set_choice,
            'l_as_list': l_as_list,
            'list_qns': list_qns,
            'comments': comments,
            'comment_len': comment_len,
        }
        return render(request, 'sitting/sitting_details.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
Ejemplo n.º 11
0
def question_end_point(request, assessment_id):
    if request.method == 'GET':
        questions = service_controller.question_management_service().list_for_assessment(assessment_id=assessment_id)
        serializer = QuestionSerializer(questions, many=True)
        json_data = serializer.data
        return Response(json_data)
Ejemplo n.º 12
0
def admin_details(request):
    if request.user.is_superuser:
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)
        user_id = request.user.id
        username = request.user.username

        admin = service_controller.admin_management_service().details(user_id)

        tutors = service_controller.tutor_management_service().list()
        tutor_len = len(tutors)

        students = service_controller.student_management_service().list()
        student_len = len(students)

        courses = service_controller.course_management_service().list()
        course_len = len(courses)

        applications = service_controller.apply_management_service().list()
        application_len = len(applications)

        appointments = service_controller.appointment_management_service(
        ).list()
        appointment_len = len(appointments)

        assessments = service_controller.assessment_management_service().list()
        assessment_len = len(assessments)

        enrollments = service_controller.enrollment_management_service().list()
        enrollment_len = len(enrollments)

        questions = service_controller.question_management_service().list()
        question_len = len(questions)

        sittings = service_controller.sitting_management_service().list()
        sitting_len = len(sittings)

        context = {
            'admin': admin,
            'tutors': tutors,
            'students': students,
            'courses': courses,
            'applications': applications,
            'appointments': appointments,
            'assessments': assessments,
            'enrollments': enrollments,
            'questions': questions,
            'sittings': sittings,
            'tutor_len': tutor_len,
            'student_len': student_len,
            'course_len': course_len,
            'appointment_len': appointment_len,
            'application_len': application_len,
            'assessment_len': assessment_len,
            'enrollment_len': enrollment_len,
            'question_len': question_len,
            'sitting_len': sitting_len,
            'username': username,
            'l_as_list': l_as_list,
        }
        return render(request, 'admin/admin_profile.html', context)
    else:
        context = {'message': 'You are not authorised!'}
        return render(request, 'error_message.html', context)