def check_student_score(): common.show_green('查看学生成绩') student_score = student_api.get_student_score(CURRENT_USER) if not student_score: common.show_red('学生成绩为空!') return common.show_info(**student_score)
def check_teach_course(): common.show_green('查看教授课程') teach_course = teacher_api.get_teach_course(CURRENT_USER) if not teach_course: common.show_red('老师教授课程列表为空!') return common.show_info(*teach_course)
def login(): common.show_green('登陆') if COOKIES['session_id']: common.show_red('用户不能重复登录') return while True: name = common.input_string('用户名') password = common.input_string('密码') params = { 'api': 'login', 'session_id': None, 'data_size': None, 'is_file': False, 'role': 'admin', 'name': name, 'password': password } res = client.send_data(params) if res['flag']: COOKIES['session_id'] = res['session_id'] COOKIES['name'] = name common.show_green(res['message']) return else: common.show_red(res['message'])
def check_student_course(): common.show_green('查看学生课程') student_course = student_api.get_student_course(CURRENT_USER) if not student_course: common.show_red('学生课程列表为空!') return common.show_info(*student_course)
def choose_teach_course(): common.show_green('选择教授课程') while True: teach_course = common.get_object_name(type_name='course') flag, msg = teacher_api.choose_teach_course(CURRENT_USER, teach_course) if not flag: common.show_red(msg) continue common.show_green(msg) return
def create_teacher(): common.show_green('创建老师') while True: name = common.input_string('老师名字') if name == 'q': break flag, msg = admin_api.create_teacher(CURRENT_USER, name) if not flag: common.show_red(msg) continue common.show_green(msg) return
def check_teach_course_student(): common.show_green('查看教授课程学生') teach_course = teacher_api.get_teach_course(CURRENT_USER) if not teach_course: common.show_red('老师教授课程列表为空!') return common.show_info(*teach_course) course_name = common.get_object_name(object_list=teach_course) teach_course_student = teacher_api.get_teach_course_student(course_name) if not teach_course_student: common.show_red('教授课程%s学生列表为空!' % course_name) return common.show_info(*teach_course_student)
def create_school(): common.show_green('创建学校') while True: name = common.input_string('学校名称') if name == 'q': break address = common.input_string('学校地址') if address == 'q': break flag, msg = admin_api.create_school(CURRENT_USER, name, address) if not flag: common.show_red(msg) continue common.show_green(msg) return
def choose_student_course(): common.show_green('选择课程') while True: course_name = common.get_object_name(type_name='course') school_name = student_api.get_school_name(course_name) if not add_course_student(course_name): return flag, msg = student_api.choose_student_course(CURRENT_USER, course_name, school_name) if not flag: common.show_red(msg) continue common.show_green(msg) return
def choose_upload_video(): upload_video_list = common.get_upload_video_list() if not upload_video_list: common.show_red('当前无可上传视频!') return while True: common.show_info(*upload_video_list) choice = common.input_integer('请选择上传视频编号') if choice == 'q': return if choice < 0 or choice > len(upload_video_list): common.show_red('选择编号非法!') continue return upload_video_list[choice]
def set_student_score(): common.show_green('修改学生成绩') while True: name = common.input_string('学生名字') if name == 'q': break course = common.input_string('学习课程') if course == 'q': break score = common.input_integer('课程成绩', is_float=True) if score == 'q': break flag, msg = teacher_api.set_student_score(CURRENT_USER, name, course, score) if not flag: common.show_red(msg) continue common.show_green(msg) return
def login(): global CURRENT_USER common.show_green('登陆') if CURRENT_USER: common.show_red('用户不能重复登录!') return while True: name = common.input_string('用户名') if name == 'q': break password = common.input_string('密码') if password == 'q': break flag, msg = teacher_api.login(name, password) if not flag: common.show_red(msg) continue CURRENT_USER = name common.show_green(msg) return
def create_course(): common.show_green('创建课程') while True: school_name = common.get_object_name(type_name='school') if not school_name: return name = common.input_string('课程名称') if name == 'q': break price = common.input_string('课程价格') if price == 'q': break cycle = common.input_string('课程周期') if cycle == 'q': break flag, msg = admin_api.create_course(CURRENT_USER, name, price, cycle, school_name) if not flag: common.show_red(msg) continue common.show_green(msg) return
def remove_video(): common.show_green('删除视频') while True: file_name = get_online_video() if not file_name: return params = { 'api': 'remove_video', 'session_id': COOKIES['session_id'], 'data_size': None, 'is_file': False, 'role': 'admin', 'file_name': file_name } res = client.send_data(params) if res['flag']: common.show_green(res['message']) return else: common.show_red(res['message'])
def release_announcement(): common.show_green('发布公告') while True: announcement = common.input_string('公告名') content = common.input_string('公告内容') params = { 'api': 'release_announcement', 'session_id': COOKIES['session_id'], 'data_size': None, 'is_file': False, 'role': 'admin', 'announcement': announcement, 'content': content } res = client.send_data(params) if res['flag']: common.show_green(res['message']) return else: common.show_red(res['message'])
def run(): menu = { '1': [login, '登陆'], '2': [check_teach_course, '查看教授课程'], '3': [check_teach_course_student, '查看教授课程学生'], '4': [choose_teach_course, '选择教授课程'], '5': [set_student_score, '修改学生成绩'] } while True: common.show_green('按"q"退出视图') common.show_menu(menu) choice = common.input_string('请选择操作编号') if choice == 'q': if CURRENT_USER: logout() return if choice not in menu: common.show_red('选择编号非法!') continue menu[choice][0]()
def run(): global client client = tcpClient.TcpClient(settings.server_address) menu = { '1': [login, '登陆'], '2': [register, '注册'], '3': [release_announcement, '发布公告'], '4': [upload_video, '上传视频'], '5': [remove_video, '删除视频'] } while True: common.show_green('按"q"登出') common.show_menu(menu) choice = common.input_string('请输入平台编号') if choice == 'q': common.show_red('logout!') return if choice not in menu: common.show_red('选择编号非法!') continue menu[choice][0]()
def get_online_video(): params = { 'api': 'get_online_video', 'session_id': COOKIES['session_id'], 'data_size': None, 'is_file': False, 'role': 'admin' } online_video_list = client.send_data(params) if not online_video_list: common.show_red('当前没有在线视频!') return while True: common.show_info(*online_video_list) choice = common.input_integer('请选择在线视频编号') if choice == 'q': return if choice < 0 or choice > len(online_video_list): common.show_red('选择编号非法!') continue return online_video_list[choice]
def upload_video(): common.show_green('上传视频') while True: file_name = choose_upload_video() if not file_name: return file_size = common.get_file_size(file_name) params = { 'api': 'upload_video', 'session_id': COOKIES['session_id'], 'data_size': None, 'is_file': True, 'role': 'admin', 'file_name': file_name, 'file_size': file_size } res = client.send_data(params) if res['flag']: common.show_green(res['message']) return else: common.show_red(res['message'])
def run(): menu = { '1': [login, '登陆'], '2': [register, '注册'], '3': [check_all_school, '查看所有学校'], '4': [check_all_teacher, '查看所有老师'], '5': [check_all_course, '查看所有课程'], '6': [create_school, '创建学校'], '7': [create_teacher, '创建老师'], '8': [create_course, '创建课程'] } while True: common.show_green('按"q"退出视图') common.show_menu(menu) choice = common.input_string('请选择操作编号') if choice == 'q': if CURRENT_USER: logout() return if choice not in menu: common.show_red('选择编号非法!') continue menu[choice][0]()
def register(): common.show_green('注册') while True: name = common.input_string('注册用户名') password = common.input_string('注册密码') password2 = common.input_string('确认密码') if password != password2: common.show_red('两次输入密码不一致!') continue params = { 'api': 'register', 'session_id': None, 'data_size': None, 'is_file': False, 'role': 'admin', 'name': name, 'password': password } res = client.send_data(params) if res['flag']: common.show_green(res['message']) return else: common.show_red(res['message'])
def run(): menu = {'1': [admin, '管理端'], '2': [user, '用户端']} while True: common.show_red('按"e"结束程序') common.show_menu(menu) choice = common.input_string('请输入平台编号') if choice == 'e': common.show_red('Goodbye!') return if choice not in menu: common.show_red('选择编号非法!') continue menu[choice][0].run()
def run(): menu = { '1': [admin, '管理端'], '2': [teacher, '教师端'], '3': [student, '学生端'], } while True: common.show_red('按"e"结束程序') common.show_menu(menu) choice = common.input_string('请选择平台编号') if choice == 'q': continue if choice == 'e': common.show_red('Goodbye!') return if choice not in menu: common.show_red('选择编号非法!') continue menu[choice][0].run()
def register(): common.show_green('注册') if CURRENT_USER: common.show_red('已登录,不能注册!') return while True: name = common.input_string('注册用户名') if name == 'q': break password = common.input_string('注册密码') if password == 'q': break password2 = common.input_string('确认密码') if password2 == 'q': break if password != password2: common.show_red('两次密码出入不一致!') continue flag, msg = admin_api.register(name, password) if not flag: common.show_red(msg) continue common.show_green(msg) return
def add_course_student(course_name): flag, msg = student_api.add_course_student(CURRENT_USER, course_name) if not flag: common.show_red(msg) common.show_green(msg) return flag
def logout(): global CURRENT_USER common.show_green('登出') common.show_red('用户%s登出!' % CURRENT_USER) CURRENT_USER = None