How to use the result.models.Course.objects.filter function in result

To help you get started, we’ve selected a few result examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abdoulrasheed / django-school-management / result / views.py View on Github external
context = {
        "courses":courses, 
        "course": course, 
        "students":students,
        }
        return render(request, 'result/add_score_for.html', context)

    if request.method == 'POST':
        ids = ()
        data = request.POST.copy()
        data.pop('csrfmiddlewaretoken', None) # remove csrf_token
        for key in data.keys():
            ids = ids + (str(key),)      # gather all the all students id (i.e the keys) in a tuple
        for s in range(0,len(ids)):      # iterate over the list of student ids gathered above
            student = TakenCourse.objects.get(id=ids[s])
            courses = Course.objects.filter(level=student.student.level).filter(semester=current_semester) # all courses of a specific level in current semester
            total_unit_in_semester = 0
            for i in courses:
                if i == courses.count():
                    break
                else:
                   total_unit_in_semester += int(i.courseUnit)
            score = data.getlist(ids[s]) # get list of score for current student in the loop
            ca = score[0]                # subscript the list to get the fisrt value > ca score
            exam = score[1]              # do thesame for exam score
            obj = TakenCourse.objects.get(pk=ids[s]) # get the current student data
            obj.ca = ca # set current student ca score
            obj.exam = exam # set current student exam score
            obj.total = obj.get_total(ca=ca,exam=exam)
            obj.grade = obj.get_grade(ca=ca,exam=exam)
            obj.comment = obj.get_comment(obj.grade)
            obj.carry_over(obj.grade)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
ids = ids + (str(key),)
        for s in range(0,len(ids)):
            student = Student.objects.get(user__pk=request.user.id)
            course = Course.objects.get(pk=ids[s])
            obj = TakenCourse.objects.create(student=student, course=course)
            obj.save()
            messages.success(request, 'Courses Registered Successfully!')
        return redirect('course_registration')
    else:
        student = Student.objects.get(user__pk=request.user.id)
        taken_courses = TakenCourse.objects.filter(student__user__id=request.user.id)
        t = ()
        for i in taken_courses:
            t += (i.course.pk,)
        current_semester = Semester.objects.get(is_current_semester=True)
        courses = Course.objects.filter(level=student.level).exclude(id__in=t)
        all_courses = Course.objects.filter(level=student.level)

        no_course_is_registered = False # Check if no course is registered
        all_courses_are_registered = False

        registered_courses = Course.objects.filter(level=student.level).filter(id__in=t)
        if registered_courses.count() == 0: # Check if number of registered courses is 0
        	no_course_is_registered = True

        if registered_courses.count() == all_courses.count():
        	all_courses_are_registered = True

        total_first_semester_unit = 0
        total_sec_semester_unit = 0
        total_registered_unit = 0
        for i in courses:
github Abdoulrasheed / django-school-management / result / views.py View on Github external
messages.success(request, 'Courses Registered Successfully!')
        return redirect('course_registration')
    else:
        student = Student.objects.get(user__pk=request.user.id)
        taken_courses = TakenCourse.objects.filter(student__user__id=request.user.id)
        t = ()
        for i in taken_courses:
            t += (i.course.pk,)
        current_semester = Semester.objects.get(is_current_semester=True)
        courses = Course.objects.filter(level=student.level).exclude(id__in=t)
        all_courses = Course.objects.filter(level=student.level)

        no_course_is_registered = False # Check if no course is registered
        all_courses_are_registered = False

        registered_courses = Course.objects.filter(level=student.level).filter(id__in=t)
        if registered_courses.count() == 0: # Check if number of registered courses is 0
        	no_course_is_registered = True

        if registered_courses.count() == all_courses.count():
        	all_courses_are_registered = True

        total_first_semester_unit = 0
        total_sec_semester_unit = 0
        total_registered_unit = 0
        for i in courses:
            if i.semester == "First":
                total_first_semester_unit += int(i.courseUnit)
            if i.semester == "Second":
                total_sec_semester_unit += int(i.courseUnit)
        for i in registered_courses:
            total_registered_unit += int(i.courseUnit)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def add_score_for(request, id):
    """ 
    Shows a page where a lecturer will add score for studens that are taking courses allocated to him
    in a specific semester and session 
    """
    current_semester = Semester.objects.get(is_current_semester=True)
    if request.method == 'GET':
        courses = Course.objects.filter(allocated_course__lecturer__pk=request.user.id).filter(semester=current_semester)
        course = Course.objects.get(pk=id)
        students = TakenCourse.objects.filter(course__allocated_course__lecturer__pk=request.user.id).filter(course__id=id).filter(course__semester=current_semester)
        context = {
        "courses":courses, 
        "course": course, 
        "students":students,
        }
        return render(request, 'result/add_score_for.html', context)

    if request.method == 'POST':
        ids = ()
        data = request.POST.copy()
        data.pop('csrfmiddlewaretoken', None) # remove csrf_token
        for key in data.keys():
            ids = ids + (str(key),)      # gather all the all students id (i.e the keys) in a tuple
        for s in range(0,len(ids)):      # iterate over the list of student ids gathered above
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def user_profile(request, id):
    """ Show profile of any selected user """
    if request.user.id == id:
        return redirect("/profile/")

    current_semester = Semester.objects.get(is_current_semester=True)
    user = User.objects.get(pk=id)
    if user.is_lecturer:
        courses = Course.objects.filter(allocated_course__lecturer__pk=id).filter(semester=current_semester)
        context = {
            "user": user,
            "courses": courses,
            }
        return render(request, 'account/user_profile.html', context)
    elif user.is_student:
        level = Student.objects.get(user__pk=id)
        courses = TakenCourse.objects.filter(student__user__id=id, course__level=level.level)
        context = {
            "user_type": "student",
            'courses': courses,
            'level': level,
            'user':user,
        }
        return render(request, 'account/user_profile.html', context)
    else:
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def add_score(request):
    """ 
    Shows a page where a lecturer will select a course allocated to him for score entry.
    in a specific semester and session 

    """
    current_session = Session.objects.get(is_current_session=True)
    current_semester = get_object_or_404(Semester, is_current_semester=True, session=current_session)
    semester = Course.objects.filter(allocated_course__lecturer__pk=request.user.id, semester=current_semester)
    courses = Course.objects.filter(allocated_course__lecturer__pk=request.user.id).filter(semester=current_semester)
    context = {
    "courses": courses,
    }
    return render(request, 'result/add_score.html', context)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def profile(request):
    """ Show profile of any user that fire out the request """
    current_semester = Semester.objects.get(is_current_semester=True)
    if request.user.is_lecturer:
        courses = Course.objects.filter(allocated_course__lecturer__pk=request.user.id).filter(semester=current_semester)
        return render(request, 'account/profile.html', {"courses": courses,})
    elif request.user.is_student:
        level = Student.objects.get(user__pk=request.user.id)
        courses = TakenCourse.objects.filter(student__user__id=request.user.id, course__level=level.level)
        context = {
        'courses': courses,
        'level': level,
        }
        return render(request, 'account/profile.html', context)
    else:
        staff = User.objects.filter(is_lecturer=True)
        return render(request, 'account/profile.html', { "staff": staff })
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def add_score(request):
    """ 
    Shows a page where a lecturer will select a course allocated to him for score entry.
    in a specific semester and session 

    """
    current_session = Session.objects.get(is_current_session=True)
    current_semester = get_object_or_404(Semester, is_current_semester=True, session=current_session)
    semester = Course.objects.filter(allocated_course__lecturer__pk=request.user.id, semester=current_semester)
    courses = Course.objects.filter(allocated_course__lecturer__pk=request.user.id).filter(semester=current_semester)
    context = {
    "courses": courses,
    }
    return render(request, 'result/add_score.html', context)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
for s in range(0,len(ids)):
            student = Student.objects.get(user__pk=request.user.id)
            course = Course.objects.get(pk=ids[s])
            obj = TakenCourse.objects.create(student=student, course=course)
            obj.save()
            messages.success(request, 'Courses Registered Successfully!')
        return redirect('course_registration')
    else:
        student = Student.objects.get(user__pk=request.user.id)
        taken_courses = TakenCourse.objects.filter(student__user__id=request.user.id)
        t = ()
        for i in taken_courses:
            t += (i.course.pk,)
        current_semester = Semester.objects.get(is_current_semester=True)
        courses = Course.objects.filter(level=student.level).exclude(id__in=t)
        all_courses = Course.objects.filter(level=student.level)

        no_course_is_registered = False # Check if no course is registered
        all_courses_are_registered = False

        registered_courses = Course.objects.filter(level=student.level).filter(id__in=t)
        if registered_courses.count() == 0: # Check if number of registered courses is 0
        	no_course_is_registered = True

        if registered_courses.count() == all_courses.count():
        	all_courses_are_registered = True

        total_first_semester_unit = 0
        total_sec_semester_unit = 0
        total_registered_unit = 0
        for i in courses:
            if i.semester == "First":