예제 #1
0
def create_teacher():
    try:
        username = input("请输入教师登录账户:")
        teacher_list = [obj.username for obj in Teacher.get_all_obj_list()]
        if username in teacher_list:
            raise Exception('\033[31;1m教师登录账户[%s] 已经存在,不可重复创建\033[0m' %
                            username)
        password = input("请输入教师登录密码:")
        name = input("请输入教师姓名:").strip()
        level = input("请输入教师级别:").strip()

        school_list = School.get_all_obj_list()
        for k, obj in enumerate(school_list):
            print(k, obj, obj.addr)
        sid = int(input('请选择学校: '))
        school_obj = school_list[sid]

        obj = Teacher(username, password, name, level, school_obj.nid)
        obj.save()
        status = True
        error = ''
        data = '\033[33;1m教师 %s [%s]创建成功\033[0m' % (obj.name, obj.username)
    except Exception as e:
        status = False
        error = str(e)
        data = ''
    return {'status': status, 'error': error, 'data': data}
예제 #2
0
def create_teacher():
    print('=================创建老师======================')
    name = input('请输入老师名字:')
    lever = input('请输入老师级别:')
    obj = Teacher(name, lever)
    obj.save()
    print('创建老师成功')
예제 #3
0
def create_teacher():
    print("=========创建老师========")
    print("学校列表")
    school_list = School.get_all_school_list()
    for k, obj in enumerate(school_list, 1):
        print(k, obj)
    sid = int(input("请选择学校选项:"))
    school_obj = school_list[sid - 1]
    name = input("请输入教师姓名")
    teacher_obj = Teacher(name, school_obj.nid)
    teacher_obj.save()
예제 #4
0
def create_teacher():
    try:
        name=input('请输入老师姓名:').strip()
        level=input('请输入老师级别:').strip()
        teacher_name_list=[obj.name for obj in Teacher.get_all_obj_list()]
        if name in teacher_name_list:
            raise Exception('\033[43;1m老师[%s] 已经存在,不可重复创建\033[0m' %(name))
        obj=Teacher(name,level)
        obj.save()
        status=True
        error=''
        data='\033[33;1m老师[%s] 级别[%s] 时间[%s] 创建成功\033[0m' %(obj.name,obj.level,obj.create_time)
    except Exception as e:
        status=False
        error=str(e)
        data=''
    return {'status':status,'error':error,'data':data}
예제 #5
0
from src.data import *  # teachers, goals
from src.models import Teacher
from src.config import db
import json

# with open("db.json", "w") as f_obj:
#     content = dict()
#
#     content.update({"goals": goals})
#     content.update({"days": days})
#     content.update({"teachers": teachers[:]})
#
#     f_obj.write(json.dumps(content))

with open("db.json", "r") as f_obj:
    content = json.loads(f_obj.read())["teachers"]
    for teacher in content:
        formed_teacher = Teacher(name=teacher["name"],
                                 description=teacher["about"],
                                 picture=teacher["picture"],
                                 rating=teacher["rating"],
                                 price=teacher["price"],
                                 goals=",".join(teacher["goals"]),
                                 free=json.dumps(teacher["free"]))
        db.session.add(formed_teacher)
        db.session.commit()