Exemple #1
0
def insert_teacher(teacher_id, name):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            sql = "insert into teacher(id,password,name) values(\
                '%s','%s','%s')" % (teacher_id, teacher_id, name)
            cursor.execute(sql)
            db.commit()
            return True
        except:
            db.rollback()
            return False
Exemple #2
0
def delete_course(course_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            sql = "delete from course where id = '%s'" % (
                course_id)
            print(sql)
            cursor.execute(sql)
            db.commit()
            return True
        except:
            db.rollback()
            return False
Exemple #3
0
def add_stu(stu_id,name,sex,birthdate,entrance_date,class_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            sql = "insert into student(id,password,name,sex,birthdate,entrance_date,class_id) values(\
                '%s','%s','%s',%s,'%s','%s','%s')" % (stu_id,stu_id,name,sex,birthdate,entrance_date,class_id)
            print(sql)
            cursor.execute(sql)
            db.commit()
            return True
        except:
            db.rollback()
            return False
Exemple #4
0
def update_stu(stu_id,name,sex,birthdate,entrance_date,class_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            sql = "update student set name = '%s', sex = %s, \
                birthdate = '%s', entrance_date='%s', class_id = '%s'\
                    where id = '%s'" % (name,sex,birthdate,entrance_date,class_id,stu_id)
            print(sql)
            cursor.execute(sql)
            db.commit()
            return True
        except:
            db.rollback()
            return False
Exemple #5
0
def get_adm_by_id(id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select * from admin where id= '%s'" % (id))
            res = cursor.fetchall()[0]
            admin = {
                'id': id,
                'name': res[1],
                'password': res[2],
            }
            return admin
        except IndexError as ie:
            print(ie)
            return None
Exemple #6
0
def get_course_by_id(course_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select * from course where id= '%s'" % (course_id))
            res = cursor.fetchall()[0]
            course = {
                'id': course_id,
                'name': res[1],
                'credit': res[2],
            }
            return course
        except IndexError as ie:
            print(ie)
            return None
Exemple #7
0
def get_tea_list():
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select id,name from teacher")
            res = cursor.fetchall()
            teacher_list = []
            for row in res:
                teacher = {}
                teacher['id'] = row[0]
                teacher['name'] = row[1]
                teacher_list.append(teacher)
            return teacher_list
        except IndexError as ie:
            print(ie)
            return None
Exemple #8
0
def get_class_list():
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select * from class")
            res = cursor.fetchall()
            class_list = []
            for row in res:
                cl = {}
                cl['id'] = row[0]
                class_list.append(cl)
            db.commit()
            return class_list
        except:
            db.rollback()
            return None
Exemple #9
0
def get_course_list():
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select id,name from course")
            res = cursor.fetchall()
            course_list = []
            for row in res:
                course = {}
                course['id'] = row[0]
                course['name'] = row[1]
                course_list.append(course)
            return course_list
        except IndexError as ie:
            print(ie)
            return None
Exemple #10
0
def get_seudent_course_bu_course_id(course_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute(
                "select * from student_course where course_id = '%s'" % (course_id))
            res = cursor.fetchall()
            stu_course_list = []
            for row in res:
                list_item = {}
                list_item['student_id'] = row[0]
                list_item['course_id'] = row[1]
                list_item['score'] = row[2]
                stu_course_list.append(list_item)
            db.commit()
            return stu_course_list
        except:
            db.rollback()
            return []
Exemple #11
0
def get_stu_by_id(id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            cursor.execute("select * from student where id= '%s'" % (id))
            res = cursor.fetchall()[0]
            student = {
                'id': id,
                'name': res[1],
                'password': res[2],
                'sex': res[3],
                'birthdate': str(res[4]),
                'entrance_date': str(res[5]),
                'class_id': str(res[6])
            }
            db.commit()
            return student
        except IndexError as ie:
            print(ie)
            return None
Exemple #12
0
def get_tea_course_class_by_course_id(course_id):
    with app.app_context():
        try:
            db = dbconnect.get_conn()
            cursor = db.cursor()
            sql = "select t.id,t.name,tcc.class_id from teacher_course_class tcc\
                join teacher t on tcc.teacher_id = t.id\
                     where tcc.course_id = '%s'" % (course_id)
            cursor.execute(sql)
            res = cursor.fetchall()
            tea_course_list = []
            for row in res:
                list_item = {}
                list_item['tea_id'] = row[0]
                list_item['tea_name'] = row[1]
                list_item['class_id'] = row[2]
                tea_course_list.append(list_item)
            db.commit()
            return tea_course_list
        except:
            db.rollback()
            return []
Exemple #13
0
"""
This script runs the URP_Server application using a development server.
"""

from os import environ
from URP_Server import app
from URP_Server.db import dbconnect

if __name__ == '__main__':
    HOST = environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    with app.app_context():
        dbconnect.get_conn()
    app.run(HOST, PORT, debug=True)