Example #1
0
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'])
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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
Example #6
0
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
Example #7
0
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
Example #8
0
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
Example #9
0
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)
Example #10
0
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
Example #11
0
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
Example #12
0
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
Example #13
0
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'])
Example #14
0
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'])
Example #15
0
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]()
Example #16
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]()
Example #17
0
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
Example #18
0
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'])
Example #19
0
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]()
Example #20
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'])
Example #21
0
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
Example #22
0
 def done_load(self, res):
     res = res.result()
     common.show_green(res)
Example #23
0
def logout():
    global CURRENT_USER
    common.show_green('登出')
    common.show_red('用户%s登出!' % CURRENT_USER)
    CURRENT_USER = None
Example #24
0
def check_all_school():
    common.show_green('查看所有学校')
    common.show_object_list(type_name='school')
Example #25
0
def check_all_teacher():
    common.show_green('查看所有老师')
    common.show_object_list(type_name='teacher')
Example #26
0
def check_all_course():
    common.show_green('查看所有课程')
    common.show_object_list(type_name='course')