How to use the result.models.TakenCourse.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
def result_sheet_pdf_view(request, id):
    current_semester = Semester.objects.get(is_current_semester=True)
    current_session = Session.objects.get(is_current_session=True)
    result = TakenCourse.objects.filter(course__pk=id)
    no_of_pass = TakenCourse.objects.filter(course__pk=id, comment="PASS").count()
    no_of_fail = TakenCourse.objects.filter(course__pk=id, comment="FAIL").count()
    fname = str(current_semester) + '_semester_' + str(current_session) + '_session_' + 'resultSheet.pdf'
    fname = fname.replace("/", "-")
    flocation = '/tmp/'+fname

    doc = SimpleDocTemplate(flocation, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0)
    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle( name="ParagraphTitle", fontSize=11, fontName="FreeSansBold"))
    Story = [Spacer(1,.2)]
    style = styles["Normal"]

    logo = MEDIA_ROOT + "/logo/android-chrome-144x144.png"
    print(logo)
    im = Image(logo, 1*inch, 1*inch)
    im.__setattr__("_offs_x", -280)
github Abdoulrasheed / django-school-management / result / models.py View on Github external
def calculate_gpa(self, total_unit_in_semester):
        current_semester = Semester.objects.get(is_current_semester=True)
        student = TakenCourse.objects.filter(student=self.student, course__level=self.student.level, course__semester=current_semester)
        p = 0
        point = 0
        for i in student:
            courseUnit = i.course.courseUnit
            if i.grade == A:
                point = 5
            elif i.grade == B:
                point = 4
            elif i.grade == C:
                point = 3
            elif i.grade == D:
                point = 2
            else:
                point = 0
            p += int(courseUnit) * point
        try:
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
            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
github Abdoulrasheed / django-school-management / result / views.py View on Github external
""" 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:
        context = {
            "user": user,
            "user_type": "superuser"
            }
        return render(request, 'account/user_profile.html', context)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def get_chart(request, *args, **kwargs):
    all_query_score = ()
    levels = (100, 200, 300, 400, 500) # all the levels in the department

    # iterate through the levels above
    for i in levels:
    	# gather all the courses registered by the students of the current level in the loop
        all_query_score += (TakenCourse.objects.filter(student__level=i),)

    # for level #100 
    first_level_total = 0

    # get the total score for all the courses registered by the students of this level
    for i in all_query_score[0]:
        first_level_total += i.total
    
    first_level_avg = 0
    if not all_query_score[0].count() == 0:
    	# calculate the average of all the students of this level
        first_level_avg = first_level_total / all_query_score[0].count()

    # do same  as above for # 200 Level students
    second_level_total = 0
    for i in all_query_score[1]:
github Abdoulrasheed / django-school-management / result / views.py View on Github external
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),)
        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
github Abdoulrasheed / django-school-management / result / models.py View on Github external
previousCGPA += i.cgpa
        cgpa = 0
        if str(current_semester) == SECOND:
            try:
                first_sem_gpa = Result.objects.get(student=self.student.id, semester=FIRST, level=self.student.level) 
                first_sem_gpa += first_sem_gpa.gpa.gpa
            except:
                first_sem_gpa = 0

            try:
                sec_sem_gpa = Result.objects.get(student=self.student.id, semester=SECOND, level=self.student.level) 
                sec_sem_gpa += sec_sem_gpa.gpa
            except:
                sec_sem_gpa = 0

            taken_courses = TakenCourse.objects.filter(student=self.student, student__level=self.student.level)
            TCU = 0
            for i in taken_courses:
                TCU += int(i.course.courseUnit)
            cpga = first_sem_gpa + sec_sem_gpa / TCU
            
            return round(cgpa, 2)
github Abdoulrasheed / django-school-management / result / views.py View on Github external
def result_sheet_pdf_view(request, id):
    current_semester = Semester.objects.get(is_current_semester=True)
    current_session = Session.objects.get(is_current_session=True)
    result = TakenCourse.objects.filter(course__pk=id)
    no_of_pass = TakenCourse.objects.filter(course__pk=id, comment="PASS").count()
    no_of_fail = TakenCourse.objects.filter(course__pk=id, comment="FAIL").count()
    fname = str(current_semester) + '_semester_' + str(current_session) + '_session_' + 'resultSheet.pdf'
    fname = fname.replace("/", "-")
    flocation = '/tmp/'+fname

    doc = SimpleDocTemplate(flocation, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0)
    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle( name="ParagraphTitle", fontSize=11, fontName="FreeSansBold"))
    Story = [Spacer(1,.2)]
    style = styles["Normal"]

    logo = MEDIA_ROOT + "/logo/android-chrome-144x144.png"
    print(logo)
    im = Image(logo, 1*inch, 1*inch)
    im.__setattr__("_offs_x", -280)
    im.__setattr__("_offs_y", -45)
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 result_sheet_pdf_view(request, id):
    current_semester = Semester.objects.get(is_current_semester=True)
    current_session = Session.objects.get(is_current_session=True)
    result = TakenCourse.objects.filter(course__pk=id)
    no_of_pass = TakenCourse.objects.filter(course__pk=id, comment="PASS").count()
    no_of_fail = TakenCourse.objects.filter(course__pk=id, comment="FAIL").count()
    fname = str(current_semester) + '_semester_' + str(current_session) + '_session_' + 'resultSheet.pdf'
    fname = fname.replace("/", "-")
    flocation = '/tmp/'+fname

    doc = SimpleDocTemplate(flocation, rightMargin=0, leftMargin=6.5 * cm, topMargin=0.3 * cm, bottomMargin=0)
    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle( name="ParagraphTitle", fontSize=11, fontName="FreeSansBold"))
    Story = [Spacer(1,.2)]
    style = styles["Normal"]

    logo = MEDIA_ROOT + "/logo/android-chrome-144x144.png"
    print(logo)
    im = Image(logo, 1*inch, 1*inch)
    im.__setattr__("_offs_x", -280)
    im.__setattr__("_offs_y", -45)
    Story.append(im)