Example #1
0
 def handle(self, *args, **kwargs):
     for i in range(100):
         name = names.get_first_name()
         lastname = names.get_last_name()
         age = int(randint(21, 85))
         teacher = Teacher(firstname=name, lastname=lastname, age=age)
         teacher.save()
Example #2
0
def login():
    ret = Teacher.login()
    if ret:
        if ret['status']:
            print(ret['data'].center(60, '-'))
            main(ret['user'])
        else:
            print(ret['error'].center(60, '-'))
Example #3
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)
        print(data)
    except Exception as e:
        status = False
        error = str(e)
        print('error: %s' % error)
        data = ''
    return {'status': status, 'error': error, 'data': data}
Example #4
0
def create_teacher():
    try:
        print('创建老师'.center(60, '='))
        name = input("请输入老师姓名: ").strip()
        level = input("请输入老师级别").strip()
        if name == '' or level == '':
            raise Exception("输入不能为空")

        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}
Example #5
0
def create_course_to_teacher():
    try:
        teacher_list = Teacher.get_all_obj_list()
        for k, obj in enumerate(teacher_list):
            print(k, obj.name)
        t_sid = input("请选择老师:")
        if t_sid.isdigit():
            t_sid = int(t_sid)
            if t_sid >= len(teacher_list):
                raise Exception("选择的老师不在此任教")
        else:
            raise Exception("选择的老师不在此任教")
        teacher_obj = teacher_list[t_sid]

        course_list = Course.get_all_obj_list()
        for k, obj in enumerate(course_list):
            print(k, obj.name)
        c_sid = input("\n请选择关联课程: ")
        if c_sid.isdigit():
            c_sid = int(c_sid)
            if c_sid >= len(course_list):
                raise Exception("没有该课程")
        else:
            raise Exception("没有该课程")
        course_obj = course_list[c_sid]

        course_to_teacher_list = [
            (obj.course_nid, obj.school_nid, obj.teacher_nid)
            for obj in Course_to_teacher.get_all_obj_list()
        ]
        if (course_obj.nid, course_obj.school_nid,
                teacher_obj.nid) in course_to_teacher_list:
            raise Exception('\033[43;1m课程[%s] 与老师[%s],不可重复关联\033[0m' %
                            (course_obj.name, teacher_obj.name))
        obj = Course_to_teacher(course_obj.nid, course_obj.school_nid,
                                teacher_obj.nid)
        obj.save()
        status = True
        error = ''
        data = '\033[33;1m课程[%s] 与老师[%s]关联成功\033[0m' % (
            (course_obj.name,
             course_obj.school_nid.get_obj_by_nid().name), teacher_obj.name)
    except Exception as e:
        status = False
        error = str(e)
        data = ''
    return {'status': status, 'error': error, 'data': data}
Example #6
0
def register():
    db_path = os.path.join(settings.ACCOUNTS_DB_DIR,'teachers')
    #print(db_path)
    exit_flag = False
    while not exit_flag :
        print("教师账号注册".center(50,"="))
        #username == student.name
        username = input("请输入您要注册的用户名【用户名必须为真实姓名】:").strip()
        if username in os.listdir(db_path):
            print("该用户名已注册,不能重新注册!")
            return False
        else:

            teacher_list= Teacher.get_all_obj_list()
            #print(student_list)
            for obj in teacher_list :
                #print(obj)
                if username == obj['name'] :
                    # student_obj = obj
                    password = input("请输入密码:").strip()
                    re_password = input('再次确认密码:').strip()
                    if password != re_password:
                        print('\033[31;1m两次输入的密码不一致!\033[0m')
                        continue
                    userdata = {
                                    "username" : username,
                                    "password" : password,
                                    'locked' : False,
                                    'authority': False,
                                    "teacher_nid" : obj['nid']
                                            }
                    dump_user(userdata,db_path )
                    print('\033[31;1m教师[%s] 注册成功!\033[0m'%username)
                    return True
            else:
                print("教师[%s] 不存在,无法注册!请联系管理员创建 教师[%s]!"%(username,username))
                    # exit_flag = True
                return False
Example #7
0
def create_course_to_teacher():
    try:
        print('关联教师与课程'.center(60, '='))
        teacher_list = Teacher.get_all_obj_list()
        for k, obj in enumerate(teacher_list):
            print('%s 老师[%s] 级别[%s]' % (k, obj['name'], obj['level']))
        id = int(input('请选择教师: '))
        teacher_obj = teacher_list[id]
        #print(teacher_obj,teacher_obj['nid'] )

        course_list = Course.get_all_obj_list()
        for k, obj in enumerate(course_list):
            print('%s [%s][%s]校区 [%s]课程 价格[%s] 周期[%s]'.center(60, '-') \
      % (k,obj['school_nid'].get_obj_by_uuid(settings.SCHOOL_DB_DIR )['name'],\
                     obj['school_nid'].get_obj_by_uuid(settings.SCHOOL_DB_DIR)['addr'], \
      obj['name'], obj['price'], obj['period']))
        id = int(input('请选择课程: '))
        course_obj = course_list[id]
        #print(course_obj )
        obj = Course_to_teacher(course_obj['nid'], course_obj['school_nid'],
                                teacher_obj['nid'])

        obj.save()
        status = True
        error = ''
        data = '\033[33;1m[%s][%s]校区 [%s]课程 关联 教师[%s] 关联成功\033[0m' %(obj.school_nid.get_obj_by_uuid(settings.SCHOOL_DB_DIR )['name'],\
                                                                     obj.school_nid.get_obj_by_uuid(settings.SCHOOL_DB_DIR)['addr'],\
                                                                    course_obj['name'],teacher_obj['name'])
        print(data)

    except Exception as e:
        status = False
        error = str(e)
        print('error: %s' % error)
        data = ''
    return {'status': status, 'error': error, 'data': data}
Example #8
0
def show_teacher():
    for obj in Teacher.get_all_obj_list():
        #print(obj)
        print('\033[33;1m老师[%s] 级别[%s] 创建时间[%s]\033[0m'.center(60,'-') \
              %(obj['name'],obj['level'],obj['create_time']))
Example #9
0
def show_teacher():
    for obj in Teacher.get_all_obj_list():
        print('\033[33;1m老师[%s] 级别[%s] 创建时间[%s]\033[0m'.center(60, '-') \
              % (obj.name, obj.level, obj.create_time))