Ejemplo n.º 1
0
def indexAllteach(request):  #查询教师授课信息
    print("查询教师授课信息")
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        cursor.execute(
            "select teach.teacher_id, teacher_name, teach.course_id, course_name from \
                        teach natural join teacher natural join course \
                        order by teach.teacher_id, teach.course_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({
                "teacher_id": r[0],
                'teacher_name': r[1],
                'course_id': r[2],
                'course_name': r[3]
            })
        return render(request, 'admin7.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 2
0
def changeTGrade(request):#录入、删除、修改所授课程学生成绩信息
    page=request.GET.get('page',1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'teacher':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        student_id = request.POST.get('student_id')
        course_id = request.POST.get('course_id')

        cursor.execute("select * from student where student_id = '%s' " % (student_id))
        student = cursor.fetchall()
        cursor.execute("select * from course where course_id = '%s' " % (course_id))
        course = cursor.fetchall()

        if operation == 'update': #修改
            grade = request.POST.get('grade')
            cursor.execute("select * from take \
                            where course_id = '%s' and student_id = '%s'" % (course_id, student_id))
            grades = cursor.fetchall()
            error_count = 0 
            if len(student) == 0:
                print("该学生不存在")
                messages.error(request,"该学生不存在")
                error_count += 1
            elif len(course) == 0:
                print("该课程不存在")
                messages.error(request,"该课程不存在") 
                error_count += 1
            elif len(grades) ==0 and (error_count == 0):
                print("该学生没有上此门课程")  
                messages.error(request,"该学生没有上此门课程") 
                error_count += 1         
            elif (ifdigit(grade) == False) or ((ifdigit(grade) == True) and ((float(grade) < 0) or (float(grade) > 100))):
                print("请输入0到100之间的数字")    
                messages.error(request,"请输入0到100之间的数字")
                error_count += 1  
            elif error_count == 0:
                grade = float(grade)
                cursor.execute('update take set \
                                grade = "%f" where (student_id = "%s") \
                                and (course_id = "%s")' % (grade, student_id, course_id))

        cursor.execute("select take.student_id,student_name,take.course_id,course_name,credits,grade \
                        from student natural join course natural join take natural join teach \
                        where teacher_id ='%s' \
                        order by take.student_id, take.course_id;" % (teacher_id))
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"student_id":r[0],'student_name':r[1],'course_id':r[2],\
                                'course_name':r[3],'credits':r[4],'grade':r[5]})
        return render(request, 'teacher3.html',pageBuilder(result_list,page))

    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 3
0
def changeallClass(request):  #录入、删除、修改班级信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        class_id = request.POST.get('class_id')
        dept = request.POST.get('dept')
        major = request.POST.get('major')

        cursor.execute("select * from class where class_id = '%s' " %
                       (class_id))
        Class = cursor.fetchall()

        if operation == 'add':  #录入
            error_count = 0
            if len(Class) != 0:
                print("此班级ID已经存在")
                messages.error(request, "此班级ID已经存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('insert into class values \
                            ("%s", "%s", "%s")' % (class_id, dept, major))

        elif operation == 'update':  #修改
            error_count = 0
            if len(Class) == 0:
                print("此班级ID不存在")
                messages.error(request, "此班级ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute(
                    'update class set dept = "%s", major = "%s" where \
                            class_id = "%s"' % (dept, major, class_id))

        elif operation == 'delete':  #删除
            error_count = 0
            if len(Class) == 0:
                print("此班级ID不存在")
                messages.error(request, "此班级ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('delete from class where class_id = "%s"' %
                               (class_id))

        cursor.execute("select * from class order by class_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"class_id": r[0], 'dept': r[1], 'major': r[2]})
        return render(request, 'admin5.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 4
0
def indexAllClass(request):  #查询班级信息
    print("查询所有班级信息")
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        cursor.execute("select * from class order by class_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"class_id": r[0], 'dept': r[1], 'major': r[2]})
        return render(request, 'admin5.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 5
0
def indexTCourse(request):#查询所授课程信息
    print("查询教师教授的课程")
    page=request.GET.get('page',1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'teacher':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        cursor.execute("select course.course_id,course_name,credits \
                        from course natural join teach \
                        where teacher_id='%s' \
                        order by course.course_id;" % (teacher_id))
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"course_id":r[0],'course_name':r[1],'credits':r[2]})
        return render(request, 'teacher2.html', pageBuilder(result_list,page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 6
0
def indexAllStu(request):  #查询所有学生信息
    print("查询所有学生信息")
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        admin_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        cursor.execute(
            "select student.student_id,password,student_name,dept,major,class.class_id \
                        from student natural join class \
                        order by student.student_id, class.class_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"student_id":r[0],'password':r[1],'student_name':r[2],\
                                'dept':r[3],'major':r[4],'class_id':r[5]})
        return render(request, 'admin2.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 7
0
def indexSGPA(request):  #查询选修成绩信息
    print("查询学生自己的成绩")
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'student':
        connection.connect()
        cursor = connection.cursor()
        cursor.execute("select t.course_id,course_name,grade\
                        from take as t,course as c\
                        where student_id=%s and t.course_id=c.course_id \
                        order by t.course_id;",
                       [request.session['id']])  #根据具体学生id查询课程成绩列表
        result_list = []
        result = cursor.fetchone()
        tmp = ('course_id', 'course_name', 'grade')
        while result:
            result_list.append(dict(zip(tmp, result)))
            result = cursor.fetchone()
        return render(request, 'student3.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 8
0
def indexTGrade(request):#查询所授课程学生成绩信息
    print("查询学生的成绩")
    page=request.GET.get('page',1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'teacher':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        cursor.execute("select take.student_id,student_name,take.course_id,course_name,credits,grade \
                        from student natural join course natural join take natural join teach \
                        where teacher_id ='%s' \
                        order by take.student_id, take.course_id;" % (teacher_id))
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"student_id":r[0],'student_name':r[1],'course_id':r[2],\
                                'course_name':r[3],'credits':r[4],'grade':r[5]})
        return render(request, 'teacher3.html',pageBuilder(result_list,page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 9
0
def indexSCourse(request):  #查询所选课程信息
    print("查询学生选课信息")
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'student':
        connection.connect()
        cursor = connection.cursor()
        cursor.execute("select t.course_id,course_name,credits\
                        from take as t,course as c\
                        where student_id=%s and t.course_id=c.course_id \
                        order by t.course_id;",
                       [request.session['id']])  #根据具体学生id查询课程信息
        tmp = ('course_id', 'course_name', 'credits')  #返回的字段名
        result_list = []
        result = cursor.fetchone()
        while result:
            result_list.append(dict(zip(tmp, result)))
            result = cursor.fetchone()
        #html网页做表格结构动态变化并且将cmd输出的内容更新到界面上进行对应显示
        return render(request, 'student2.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 10
0
def changeallteach(request):  #录入、删除教师授课信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        teacher_id = request.POST.get('teacher_id')
        course_id = request.POST.get('course_id')

        cursor.execute("select * from teacher where teacher_id = '%s' " %
                       (teacher_id))
        teacher = cursor.fetchall()
        cursor.execute("select * from course where course_id = '%s' " %
                       (course_id))
        course = cursor.fetchall()

        cursor.execute("select * from teach where \
                        teacher_id = '%s' and course_id = '%s'" %
                       (teacher_id, course_id))
        tea_course = cursor.fetchall()

        if operation == 'add':  #录入

            error_count = 0
            if len(teacher) == 0:
                print("该教师ID不存在")
                messages.error(request, "该教师ID不存在")
                error_count += 1
            elif len(course) == 0:
                print("该课程ID不存在")
                messages.error(request, "该课程ID不存在")
                error_count += 1
            elif len(tea_course) != 0:
                print("此教师已经教授该课程")
                messages.error(request, "此教师已经教授该课程")
                error_count += 1
            elif error_count == 0:
                grade = 0
                cursor.execute('insert into teach values \
                            ("%s", "%s")' % (teacher_id, course_id))

        elif operation == 'delete':  #删除

            error_count = 0
            if len(teacher) == 0:
                print("该教师ID不存在")
                messages.error(request, "该教师ID不存在")
                error_count += 1
            elif len(course) == 0:
                print("该课程ID不存在")
                messages.error(request, "该课程ID不存在")
                error_count += 1
            elif len(tea_course) == 0:
                print("此教师并未教授该课程")
                messages.error(request, "此教师并未教授该课程")
                error_count += 1
            elif error_count == 0:
                cursor.execute(
                    'delete from teach where teacher_id = "%s" and course_id = "%s"'
                    % (teacher_id, course_id))

        cursor.execute(
            "select teach.teacher_id, teacher_name, teach.course_id, course_name from \
                        teach natural join teacher natural join course \
                        order by teach.teacher_id, teach.course_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({
                "teacher_id": r[0],
                'teacher_name': r[1],
                'course_id': r[2],
                'course_name': r[3]
            })
        return render(request, 'admin7.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 11
0
def changealltake(request):  #录入、删除学生选课信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        student_id = request.POST.get('student_id')
        course_id = request.POST.get('course_id')

        cursor.execute("select * from student where student_id = '%s' " %
                       (student_id))
        student = cursor.fetchall()
        cursor.execute("select * from course where course_id = '%s' " %
                       (course_id))
        course = cursor.fetchall()
        cursor.execute("select * from take where \
                        student_id = '%s' and course_id = '%s'" %
                       (student_id, course_id))
        stu_class = cursor.fetchall()

        if operation == 'add':  #录入

            error_count = 0
            if len(student) == 0:
                print("该学生ID不存在")
                messages.error(request, "该学生ID不存在")
                error_count += 1
            elif len(course) == 0:
                print("该课程ID不存在")
                messages.error(request, "该课程ID不存在")
                error_count += 1
            elif len(stu_class) != 0:
                print("此学生已经选中该课程")
                messages.error(request, "此学生已经选中该课程")
                error_count += 1
            elif error_count == 0:
                grade = 0
                cursor.execute('insert into take values \
                            ("%s", "%s", "%f")' %
                               (student_id, course_id, grade))

        elif operation == 'delete':  #删除

            error_count = 0
            if len(student) == 0:
                print("该学生ID不存在")
                messages.error(request, "该学生ID不存在")
                error_count += 1
            elif len(course) == 0:
                print("该课程ID不存在")
                messages.error(request, "该课程ID不存在")
                error_count += 1
            elif len(stu_class) == 0:
                print("此学生并未选中该课程")
                messages.error(request, "此学生并未选中该课程")
                error_count += 1
            elif error_count == 0:
                cursor.execute('delete from take \
                    where student_id = "%s" and course_id = "%s"' %
                               (student_id, course_id))

        cursor.execute(
            "select take.student_id, student_name, take.course_id, course_name from \
                        take natural join student natural join course \
                        order by take.student_id, take.course_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({
                "student_id": r[0],
                'student_name': r[1],
                'course_id': r[2],
                'course_name': r[3]
            })
        return render(request, 'admin6.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 12
0
def changeAllCourse(request):  #录入、删除、修改课程信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        course_id = request.POST.get('course_id')

        cursor.execute("select * from course where course_id = '%s' " %
                       (course_id))
        course = cursor.fetchall()

        if operation == 'add':  #录入
            course_name = request.POST.get('course_name')
            credit = request.POST.get('credits')
            error_count = 0
            if len(course) != 0:
                print("此课程ID已经存在")
                messages.error(request, "此课程ID已经存在")
                error_count += 1
            elif (ifdigit(credit) == False) or ((ifdigit(credit) == True) and
                                                (float(credit) < 0)):
                print("您输入的学分不是大于0的数字!")
                messages.error(request, "您输入的学分不是大于0的数字!")
                error_count += 1
            elif error_count == 0:
                credit = float(credit)
                cursor.execute('insert into course values \
                            ("%s", "%s", "%f")' %
                               (course_id, course_name, credit))

        elif operation == 'update':  #修改
            course_name = request.POST.get('course_name')
            credit = request.POST.get('credits')
            cursor.execute(
                "select * from course where course_id = '%s' and course_name = '%s' "
                % (course_id, course_name))
            class_course = cursor.fetchall()

            error_count = 0
            if len(course) == 0:
                print("此课程ID不存在")
                messages.error(request, "此课程ID不存在")
                error_count += 1
            elif len(class_course) == 0 and error_count == 0:
                print("此课程ID与课程名不对应")
                messages.error(request, "此课程ID与课程名不对应")
                error_count += 1
            elif (ifdigit(credit) == False) or ((ifdigit(credit) == True) and
                                                (float(credit) < 0)):
                print(float(credit))
                print("您输入的学分不是大于0的数字!")
                messages.error(request, "您输入的学分不是大于0的数字!")
                error_count += 1
            elif error_count == 0:
                credit = float(credit)
                cursor.execute(
                    'update course set course_name = "%s", credits = "%f" where \
                            course_id = "%s"' %
                    (course_name, credit, course_id))

        elif operation == 'delete':  #删除
            error_count = 0
            if len(course) == 0:
                print("此课程ID不存在")
                messages.error(request, "此课程ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('delete from course where course_id = "%s"' %
                               (course_id))

        cursor.execute("select * from course order by course_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({
                "course_id": r[0],
                'course_name': r[1],
                'credits': r[2]
            })
        return render(request, 'admin4.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 13
0
def changeAllTeacher(request):  #录入、删除、修改教师信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        teacher_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        teacher_id = request.POST.get('teacher_id')
        cursor.execute("select * from teacher where teacher_id = '%s' " %
                       (teacher_id))
        teacher = cursor.fetchall()

        if operation == 'add':  #录入
            password = request.POST.get('password')
            teacher_name = request.POST.get('teacher_name')
            dept = request.POST.get('dept')

            error_count = 0
            if len(teacher) != 0:
                print("此教师ID已经存在")
                messages.error(request, "此教师ID已经存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('insert into teacher values \
                            ("%s", md5("%s"), "%s", "%s")' %
                               (teacher_id, password, teacher_name, dept))

        elif operation == 'update':  #修改
            password = request.POST.get('password')
            teacher_name = request.POST.get('teacher_name')
            dept = request.POST.get('dept')

            error_count = 0
            if len(teacher) == 0:
                print("此教师ID不存在")
                messages.error(request, "此教师ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute(
                    'update teacher set password = md5("%s"), teacher_name = "%s", dept = "%s" \
                            where teacher_id = "%s"' %
                    (password, teacher_name, dept, teacher_id))

        elif operation == 'delete':  #删除
            error_count = 0
            if len(teacher) == 0:
                print("此教师ID不存在")
                messages.error(request, "此教师ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('delete from teacher where teacher_id = "%s"' %
                               (teacher_id))

        cursor.execute("select * from teacher order by teacher_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({
                "teacher_id": r[0],
                "password": r[1],
                'teacher_name': r[2],
                'dept': r[3]
            })
        return render(request, 'admin3.html', pageBuilder(result_list, page))
    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')
Ejemplo n.º 14
0
def changeAllStu(request):  #录入、删除、修改学生信息
    page = request.GET.get('page', 1)
    if 'sessionid' in request.COOKIES and request.session['role'] == 'admin':
        admin_id = request.session['id']
        connection.connect()
        cursor = connection.cursor()
        operation = request.POST.get('my_select')
        student_id = request.POST.get('student_id')

        cursor.execute("select * from student where student_id = '%s' " %
                       (student_id))
        student = cursor.fetchall()

        if operation == 'add':  #录入
            password = request.POST.get('password')
            student_name = request.POST.get('student_name')
            class_id = request.POST.get('class_id')

            cursor.execute("select * from class where class_id = '%s' " %
                           (class_id))
            Class = cursor.fetchall()

            error_count = 0
            if len(student) != 0:
                print("此学生ID已经存在")
                messages.error(request, "此学生ID已经存在")
                error_count += 1
            elif len(Class) == 0:
                print("该班级不存在")
                messages.error(request, "该班级不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('insert into student values \
                                ("%s", md5("%s"), "%s", "%s")' %
                               (student_id, password, student_name, class_id))

        elif operation == 'update':  #修改
            password = request.POST.get('password')
            student_name = request.POST.get('student_name')
            class_id = request.POST.get('class_id')

            cursor.execute("select * from class where class_id = '%s' " %
                           (class_id))
            Class = cursor.fetchall()
            cursor.execute(
                "select * from student where student_id = '%s' and class_id = '%s'"
                % (student_id, class_id))
            stu_class = cursor.fetchall()

            error_count = 0
            if len(student) == 0:
                print("此学生ID不存在")
                messages.error(request, "此学生ID不存在")
                error_count += 1
            elif len(Class) == 0:
                print("该班级不存在")
                messages.error(request, "该班级不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute(
                    'update student set password = md5("%s"), student_name = "%s", class_id = "%s" where \
                            student_id = "%s"' %
                    (password, student_name, class_id, student_id))

        elif operation == 'delete':  #删除
            error_count = 0
            if len(student) == 0:
                print("此学生ID不存在")
                messages.error(request, "此学生ID不存在")
                error_count += 1
            elif error_count == 0:
                cursor.execute('delete from student where student_id = "%s"' %
                               (student_id))

        cursor.execute(
            "select student.student_id,password,student_name,dept,major,class.class_id \
                        from student natural join class \
                        order by student.student_id, class.class_id;")
        result = cursor.fetchall()
        connection.close()
        result_list = []
        for r in result:
            result_list.append({"student_id":r[0],'password':r[1],'student_name':r[2],\
                                'dept':r[3],'major':r[4],'class_id':r[5]})
        return render(request, 'admin2.html', pageBuilder(result_list, page))

    else:
        print("用户身份不合法")
        return redirect('/pro/illegalUser/')