def show_classes(user, **kwargs): """ 显示讲师的班级列表 :param user: :param kwargs: :return: """ teacher = LuffyTeacher.fetch_one(user.sn) classes = teacher.classes() if not len(classes): print("没有班级记录") return False records = [] for sn in classes: entry = LuffyClass.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 Models.add_duty( user, **{ 'class': records[index], 'logger': kwargs.get('logger') })
def profile(user): """ 显示个人信息 :return: """ info = LuffyTeacher.fetch_one(user.sn) print(info)
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 show_duties(user, **kwargs): teacher = LuffyTeacher.fetch_one(user.sn) duties = teacher.duties() if not len(duties): print("没有执勤记录") return False for i, row in enumerate(duties, 1): print('# ', i, row) return duties
def authenticate(**kwargs): """ 登录认证 :param kwargs: :return: """ username = kwargs.get('username') password = kwargs.get('password') records = LuffyTeacher.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 __str__(self): return "班级:%s 学校:%s 课程:%s 讲师:%s 学员数:%d" % ( self.title, LuffySchool.fetch_one(self.school_sn).title, LuffyCourse.fetch_one( self.course_sn).title, LuffyTeacher.fetch_one( self.teacher_sn).username, len(self.__students))