コード例 #1
0
    sectionNo = i[2]
    section_id = Section_T.objects.raw('''
        SELECT *
        FROM mainapp_section_t
        WHERE course_id = '{}' AND sectionNo = {};
    '''.format(courseID, sectionNo))

    for j in range(1, len(co) + 1):
        assessment_id = Assessment_T.objects.raw('''
            SELECT *
            FROM mainapp_assessment_t
            WHERE section_id = {} AND co_id IN (
                SELECT id
                FROM mainapp_co_t
                WHERE course_id = '{}' AND coNo = {}
            )
        '''.format(section_id[0].id, courseID, j))
        enrollment_id = Enrollment_T.objects.raw('''
            SELECT *
            FROM mainapp_enrollment_t
            WHERE student_id = '{}' AND section_id = {}
        '''.format(i[0], section_id[0].id))
        # evaluation = Evaluation_T(enrollment_id=enrollment_id[0].enrollmentID, assessment_id=assessment_id, obtainedMarks=i[j + 4])
        # evaluation = Evaluation_T(student_id=i[0], assessment_id=assessment_id[0].assessmentNo, obtainedMarks=i[j + 3])
        # try:
        evaluation = Evaluation_T(enrollment_id=enrollment_id[0].enrollmentID,
                                  assessment_id=assessment_id[0].assessmentNo,
                                  obtainedMarks=i[j + 3])
        evaluation.save()
        # except:
        #     continue
コード例 #2
0
ファイル: views.py プロジェクト: saditahmid/spm
def evaluation(request):
    if request.method == 'POST':
        course_id = request.POST.get('course-id')
        section = request.POST.get('section')
        semester = request.POST.get('semester')
        year = request.POST.get('year')
        
        student_id = request.POST.getlist('student_id')
        coMarks = []
        for i in range(len(student_id)):
            coMarks.append(request.POST.getlist(f'coMarks{i}'))
        
        section_id = None
        try:
            section_id = Section_T.objects.raw('''
                SELECT *
                FROM mainapp_section_t
                WHERE course_id = '{}' AND sectionNo = {};
            '''.format(course_id, section))
            section_id = section_id[0].id
        except:
            section_id = None
        assessment_list = []
        coLength = 0
        try:
            coLength = len(coMarks[0]) + 1
        except:
            coLength = 0
        for j in range(1, coLength):
            assessment_id = None
            try:
                assessment_id = Assessment_T.objects.raw('''
                    SELECT *
                    FROM mainapp_assessment_t
                    WHERE section_id = {} AND co_id IN (
                        SELECT id
                        FROM mainapp_co_t
                        WHERE course_id = '{}' AND coNo = {}
                    )
                '''.format(section_id, course_id, j))
                assessment_list.append(assessment_id[0].assessmentNo)
            except:
                assessment_id = None
                assessment_list.append(assessment_id)
        
        for i in range(len(student_id)):
            enrollment_id = None
            try:
                enrollment_id = Enrollment_T.objects.raw('''
                    SELECT *
                    FROM mainapp_enrollment_t
                    WHERE student_id = '{}' AND section_id = {}
                '''.format(student_id[i], section_id))
                enrollment_id = enrollment_id[0].enrollmentID
            except:
                enrollment_id = None
                
            if enrollment_id is None:
                enrollment = Enrollment_T(student_id=student_id[i], section_id=section_id, semester=semester, year=year)
                enrollment.save()
                enrollment_id = enrollment.enrollmentID
            
            for j in range(len(assessment_list)):
                evaluation = Evaluation_T(enrollment_id=enrollment_id, assessment_id=assessment_list[j], obtainedMarks=coMarks[i][j])
                evaluation.save()
                
        return redirect('dataentry')