def regist(**kwargs): """ 学生注册 :param kwargs: :return: """ username = input("请输入用户名(b,返回):>>").strip() if username.lower() == 'b': return False password = input("请输入登录密码:>>").strip() if not len(password): print('密码不得为空') return False schools = LuffySchool.fetch_all() print("学校列表") if not len(schools): print("没有找到学校") return [] for i, entry in enumerate(schools, 1): print('# ', i, entry) entry_id = input("请输入所属学校序号:>>").strip() index = int(entry_id) - 1 if index < 0 or index >= len(schools): print("错误的选项") return False entry = LuffyStudent(username, password, schools[index].sn) entry.save() logger = kwargs.get('logger') if logger: logger.log("用户 %s 注册成功" % username) print("注册成功") return True
def sign_up(user, **kwargs): selected = kwargs.get('class', False) if not selected: print("班级参数异常") return False student = LuffyStudent.fetch_one(user.sn) course = LuffyCourse.fetch_one(selected.course_sn) if float(student.get_balance()) < float(course.price): print('余额不足') return False # 更新学生余额及消费记录信息 student.add_balance(-1 * float(course.price)) student.add_transaction( '%s 报名课程:%s 价格:%s' % (utils.calculate_date(time_format=True), course.title, str(course.price))) student.save() # 更新班级学生列表 selected.add_student(student.sn) selected.save() # 更新班级讲师的学生列表 teacher = LuffyTeacher.fetch_one(selected.teacher_sn) teacher.add_student(student.sn) teacher.save() return {'status': 0, 'logger': kwargs.get('logger'), 'msg': "报名课程:%s 价格:%s" % (course.title, str(course.price))}
def profile(user): """ 显示个人信息 :return: """ info = LuffyStudent.fetch_one(user.sn) print(info)
def show_transactions(user, **kwargs): student = LuffyStudent.fetch_one(user.sn) transactions = student.transactions() if not len(transactions): print("没有交易记录") return False for i, row in enumerate(transactions, 1): print('# ', i, row)
def recharge(user, **kwargs): """ 创建班级 :param user: :param kwargs: :return: """ amount = input("请输入充值金额,(b,返回):>>").strip() if amount.lower() == 'b': return False if not amount.isdigit() and not utils.is_float_num(amount): print("请输入数字字符") return False entry = LuffyStudent.fetch_one(user.sn) entry.add_balance(float(amount)) entry.add_transaction('%s 充值:%s' % (utils.calculate_date(time_format=True), amount)) entry.save() return {'status': 0, 'logger': kwargs.get('logger'), 'msg': "学生 %s 成功充值 %s " % (entry.username, amount)}
def authenticate(**kwargs): """ 登录认证 :param kwargs: :return: """ username = kwargs.get('username') password = kwargs.get('password') records = LuffyStudent.fetch_all() if not len(records): return False student = None for entry in records: if entry.username == username and utils.hash_md5(password): student = entry break if student: logger = kwargs.get('logger') if logger: logger.log("学生%s登录系统" % username) return student return False
def show_students(user, **kwargs): """ 显示讲师的学生列表 :param user: :param kwargs: :return: """ teacher = LuffyTeacher.fetch_one(user.sn) students = teacher.students() if not len(students): print("没有学生记录") return False records = [] for sn in students: entry = LuffyStudent.fetch_one(sn) if entry: records.append(entry) if not len(records): print("没有学生记录") return False for i, row in enumerate(records, 1): print('# ', i, row) option = input("请输入要打分的学生ID(b,返回):>>").strip() if option.lower() == 'b': return False index = int(option) - 1 if index < 0 or index >= len(records): print("错误的选项") return False score = input("请输入分值:>>").strip() if not score.isdigit() and not utils.is_float_num(score): print("请输入数字字符") return False Models.set_score( user, **{ 'student': records[index], 'score': score, 'logger': kwargs.get('logger') })
def set_score(user, **kwargs): """ 给学生打分 :param user: :param kwargs: :return: """ selected = kwargs.get('student', False) score = kwargs.get('score', 0) if not selected: print("学生参数异常") return False student = LuffyStudent.fetch_one(selected.sn) student.set_score(score) student.save() return { 'status': 0, 'logger': kwargs.get('logger'), 'msg': "讲师 %s 修改学员 %s 分值为:%s" % (user.username, student.username, str(score)) }
def show_scores(user, **kwargs): student = LuffyStudent.fetch_one(user.sn) print(student.score())