def delete_sitting(request, sitting_id): if request.user.is_superuser: service_controller.sitting_management_service().delete(sitting_id) return redirect('admin_details') else: context = {'message': 'You are not authorised'} return render(request, 'error_message.html', context)
def pending_assessments(request): if request.method == 'GET': if request.user.student_set.exists(): user_id = request.user.id student = service_controller.student_management_service().details( user_id) student_id = student.id assessments = service_controller.assessment_management_service( ).list_assessment_for_student(student_id) sittings = service_controller.sitting_management_service( ).list_of_sitting_for_student_assessment(student_id) enrollments = service_controller.enrollment_management_service( ).list_enrollment_for_student(student_id) assessment_listing: ListAssessmentDto() = [] if sittings == []: serializer = PendingAssessments(assessments, many=True) json_data = serializer.data return Response(json_data) else: for assessment in assessments: for sitting in sittings: if assessment.id != sitting.assessment_id and assessment.status == True: assessment_listing.append(assessment) serializer = PendingAssessments(assessment_listing, many=True) json_data = serializer.data return Response(json_data)
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
def list_submissions(request): if request.method == "GET": if request.user.student_set.exists(): user_id = request.user.id student = service_controller.student_management_service().details( user_id=user_id) student_id = student.id sitting_list: List = service_controller.sitting_management_service( ).list_of_sitting_for_student_assessment(student_id) serializer = Submissions(sitting_list, many=True) json_data = serializer.data return Response(json_data) elif request.user.tutor_set.exists(): user_id = request.user.id tutor = service_controller.tutor_management_service().details( user_id) tutor_id = tutor.id assessments = service_controller.assessment_management_service( ).list_assessment_for_tutor(tutor_id) sittings = service_controller.sitting_management_service().list() sitting_list: List = [] for sitting in sittings: for assessment in assessments: if assessment.id == sitting.assessment_id: sitting_list.append(sitting) serializer = Submissions(sitting_list, many=True) json_data = serializer.data return Response(json_data) elif request.user.adminuser_set.exists(): user_id = request.user.id admin = service_controller.admin_management_service().details( user_id=user_id) admin_id = admin.id sittings = service_controller.sitting_management_service().list() serializer = Submissions(sittings, many=True) json_data = serializer.data return Response(json_data)
def student_details_for_admin(request, student_id): if request.user.has_perm('lms_app.view_student'): l_as_list = [] for g in request.user.groups.all(): l_as_list.append(g.name) username = request.user.username student_ = Student.objects.get(id=student_id) student_id = student_.id user_id = student_.user.id student = service_controller.student_management_service().details(user_id) enrollments = service_controller.enrollment_management_service().list_enrollment_for_student(student_id) enrollment_len = len(enrollments) # Getting all Assessments for Student assessments = service_controller.assessment_management_service().list_assessment_for_student(student_id) assessment_len = len(assessments) # Getting all sittings and attempted assessments by Student sittings = service_controller.sitting_management_service().list_of_sitting_for_student_assessment(student_id) sitting_len = len(sittings) sitting_list = [] for sitting in sittings: for assessment in assessments: if sitting.assessment_id == assessment.id: sitting_list.append(sitting.assessment_id) context = { 'student': student, 'enrollments': enrollments, 'enrollment_len': enrollment_len, 'sitting_len': sitting_len, 'sitting_list': sitting_list, 'assessments': assessments, 'assessment_len': assessment_len, 'username': username, 'sittings': sittings, 'l_as_list': l_as_list, } return render(request, 'student/student_profile.html', context) else: context={ 'message': 'You are not authorised' } return render(request, 'error_message.html', context)
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)
def list_sittings(request): 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 sittings = service_controller.sitting_management_service().list() context = { 'username': username, 'sittings': sittings, 'l_as_list': l_as_list, } return render(request, 'sitting/list_sitting.html', context) else: context = {'message': 'You are not authorised'} return render(request, 'error_message.html', context)
def __new_sitting_method(request, sitting_answer_list, sitting_question_list, student_id, assessment_id, context): if request.method == 'POST': try: sitting = __set_sitting_attribute_request( request, sitting_answer_list=sitting_answer_list, sitting_question_list=sitting_question_list, student_id=student_id, assessment_id=assessment_id) sitting.user_answer = __get_answers_from_cookies(request) solved_assessment = service_controller.sitting_management_service( ).register(sitting) context['saved'] = 'success' return solved_assessment except Exception as e: print('This Sitting Creation could not be completed') raise e
def list_of_late_submissions_for_tutors(request): if request.method == 'GET': user_id = request.user.id tutor = service_controller.tutor_management_service().details(user_id) tutor_id = tutor.id assessments = service_controller.assessment_management_service( ).list_assessment_for_tutor(tutor_id) sittings = service_controller.sitting_management_service().list() sitting_list: List = [] for sitting in sittings: for assessment in assessments: if assessment.date_due <= sitting.date_submitted: if assessment.time_due <= sitting.time_submitted: sitting_list.append(sitting) serializer = Submissions(sitting_list, many=True) json_data = serializer.data return Response(json_data)
def list_assessments_for_students(request): if request.user.has_perm('lms_app.view_assessment'): 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 = service_controller.student_management_service().details( user_id) student_id = student.id assessments = service_controller.assessment_management_service( ).list_assessment_for_student(student_id) assessment_len = len(assessments) sittings = service_controller.sitting_management_service( ).list_of_sitting_for_student_assessment(student_id) sitting_list = [] for sitting in sittings: for assessment in assessments: if sitting.assessment_id == assessment.id: sitting_list.append(sitting.assessment_id) context = { 'username': username, 'assessments': assessments, 'student_id': student_id, 'presently': 'Assessments', 'sitting_list': sitting_list, 'assessment_len': assessment_len, 'l_as_list': l_as_list, } return render(request, 'student/student_assessments.html', context) else: context = {'message': 'You are not authorised'} return render(request, 'error_message.html', context)
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)
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)