예제 #1
0
def __create_if_post_method(request, context):
    if request.method == 'POST':
        try:
            course = __set_course_attribute_request(request)
            service_controller.course_management_service().register(course)
            context['saved'] = 'success'
        except Exception as e:
            print('This Course was not registered')
            raise e
예제 #2
0
def course_delete(request, course_id):
    if request.user.has_perm('lms_app.delete_course'):
        try:
            service_controller.course_management_service().delete(course_id)
            redirect('admin_details')
        except Course.DoesNotExist as e:
            print('This course does not exist!')
            raise e
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
예제 #3
0
def edit_course(request, course_id):
    if request.user.has_perm('lms_app.change_course'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)
        try:
            course = service_controller.course_management_service().details(
                course_id)
        except Course.DoesNotExist as e:
            print('Course not registered yet!')
            raise e

        context = {
            'course': course,
            'l_as_list': l_as_list,
        }
        edited_course = __edit_if_post_method(request, course_id, context)
        if edited_course is not None:
            context['course'] = edited_course
            messages.success(request, message='Changes Saved!')
            return redirect('course_details', course_id)
        return render(request, 'course/edit_course.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
예제 #4
0
def list_courses(request):
    l_as_list = []
    for g in request.user.groups.all():
        l_as_list.append(g.name)

    username = request.user.username
    courses = service_controller.course_management_service().list()
    context = {
        'username': username,
        'courses': courses,
        'l_as_list': l_as_list,
    }
    return render(request, 'course/list_courses.html', context)
예제 #5
0
def search_course(request):
    search = request.POST.get('search_course').upper()
    courses = service_controller.course_management_service().list()
    search_list = []
    for course in courses:
        course_title = str(course.course_title).upper()
        course_slug = str(course.course_slug).upper()
        if search.upper() in course_title or search in course_slug:
            search_list.append(course)

    context = {
        'courses': search_list,
    }
    return render(request, 'course/list_courses.html', context)
예제 #6
0
def list_tutor_for_appointment(request, course_id):
    if request.user.is_superuser:
        username = request.user.username

        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)
        course = service_controller.course_management_service().details(
            course_id)
        appointments = service_controller.appointment_management_service(
        ).list_tutor_for_course_appointed(course_id)
        context = {
            'l_as_list': l_as_list,
            'username': username,
            'appointments': appointments,
            'course': course,
        }
        return render(request, 'appointment/list_appointment.html', context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
예제 #7
0
def list_enrollments(request, course_id):
    if request.user.has_perm('lms_app.view_enrollment'):
        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        username = request.user.username
        enrollments = service_controller.enrollment_management_service().list_student_for_enrollment(course_id)
        course = service_controller.course_management_service().details(course_id)
        context = {
            'enrollments': enrollments,
            'username': username,
            'l_as_list': l_as_list,
            'course': course,
        }
        return render(request, 'enrollment/list_enrollment.html', context)
    else:
        context={
            'message': 'You are not authorised'
        }
        return render(request, 'error_message.html', context)
예제 #8
0
def start_appointment(request):
    if request.user.is_superuser:
        username = request.user.username

        l_as_list = []
        for g in request.user.groups.all():
            l_as_list.append(g.name)

        applications = service_controller.apply_management_service().list()
        courses = service_controller.course_management_service().list()
        tutors = service_controller.tutor_management_service().list()

        context = {
            'username': username,
            'l_as_list': l_as_list,
            'applications': applications,
            'courses': courses,
            'tutors': tutors,
        }
        return render(request, 'appointment/initiate_appointment.html',
                      context)
    else:
        context = {'message': 'You are not authorised'}
        return render(request, 'error_message.html', context)
예제 #9
0
def course_details(request, course_id):
    l_as_list = []
    for g in request.user.groups.all():
        l_as_list.append(g.name)

    username = request.user.username
    course = service_controller.course_management_service().details(
        course_id=course_id)
    tutor_list = []
    student_list = []
    apply_list = []
    students_for_course = service_controller.student_management_service(
    ).list_student_for_course(course_id)
    tutor_for_course = service_controller.appointment_management_service(
    ).list_tutor_for_course_appointed(course_id)

    if 'students' in l_as_list:
        user_id = request.user.id
        student_id = service_controller.student_management_service().details(
            user_id).id

        for student in students_for_course:
            if student_id == student.id:
                student_list.append(student_id)

        enrollments = service_controller.enrollment_management_service(
        ).list_enrollment_for_student(student_id)
        if len(enrollments) == 0:
            enrollment = 0
        else:
            for enroll in enrollments:
                if course_id == enroll.course_id:
                    enrollment = enroll.id
                else:
                    enrollment = 0

        tutor_id = 0

    elif 'tutors' in l_as_list:
        user_id = request.user.id
        tutor_id = service_controller.tutor_management_service().details(
            user_id).id
        applications = service_controller.apply_management_service().list()

        for tutor in tutor_for_course:
            if tutor_id == tutor.tutors_id:
                tutor_list.append(tutor_id)

        for application in applications:
            if tutor_id == application.tutor_id and course_id == application.course_id:
                apply_list.append(tutor_id)

        student_id = 0
        enrollment = 0

    elif 'admin' in l_as_list:
        enrollment = 0
        student_id = 0
        tutor_id = 0

    elif l_as_list == None:
        enrollment = 0
        student_id = 0
        tutor_id = 0

    context = {
        'username': username,
        'l_as_list': l_as_list,
        'course': course,
        'student_list': student_list,
        'apply_list': apply_list,
        'student_id': student_id,
        'tutor_list': tutor_list,
        'tutor_id': tutor_id,
        'enrollment': enrollment,
    }
    return render(request, 'course/course_details.html', context)
예제 #10
0
def list_all_courses(request):
    courses = service_controller.course_management_service().list()
    serializer = Courses(courses, many=True)
    json_data = serializer.data
    return Response(json_data)
예제 #11
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)