def add(cname, ctype, classweek, classtime, rid, tid, credit, cnum, caid): now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) course = Courses(cname=cname, ctype=ctype, classweek=classweek, classtime=classtime, rid=rid, tid=tid, cretime=now_time, updtime=now_time, credit=credit, cnum=cnum, caid=caid) try: db.session.add(course) db.session.commit() return True except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) try: db.session.rollback() except Exception as ex: print(ex) ExceptionLog.other_error(ex.__str__()) return False
def admin_change_pwd(id, old_pwd, new_pwd1, new_pwd2): if new_pwd1 != new_pwd2: return False old_pwd = Encryption.md5(old_pwd) try: admin = Admins.query.get(id) if admin.password != old_pwd: return False admin.password = Encryption.md5(new_pwd1) db.session.add(admin) db.session.commit() return True except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) try: db.session.rollback() except Exception as ex: print(ex) ExceptionLog.other_error(ex.__str__()) return False
def update(cid, cname, ctype, classweek, classtime, classplace, tid, credit): try: course = Courses.query.get(cid) # 获取原来的信息 # 修改信息 course.cname = cname course.ctype = ctype course.classweek = classweek course.classtime = classtime course.classplace = classplace course.tid = tid course.credit = credit db.session.add(course) db.session.commit() return True except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) try: db.session.rollback() except Exception as ex: print(ex) ExceptionLog.other_error(ex.__str__()) return False
def get_apply_course(cls): try: course_li = Courses.query.filter_by(isexamine=0) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__())
def get_by_id(cls, rid): try: room = Classrooms.query.get(rid) return cls.list_to_dict([room])[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_caid(cls, caid): try: room_li = Classrooms.query.filter_by(caid=caid) return cls.list_to_dict(room_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_place(cls, classplace): try: course_li = Courses.query.filter_by(classplace=classplace) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_all(cls): try: level_li = Levels.query.all() return cls.list_to_dict(level_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_cid(cls, cid): try: cosel_li = Selcourses.query.filter_by(cid=cid) return cls.list_to_dict(cosel_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_end(cls): try: seltime = Coseltime.query.filter_by(isend=1) return cls.list_to_dict(seltime) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_tid_pass(cls, tid): try: course_li = Courses.query.filter_by(tid=tid, ispass=1, isexamine=1) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_all(cls): try: admin_li = Admins.query.filter_by(issuper=0) return cls.list_to_dict(admin_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_all(cls): try: seltime_li = Coseltime.query.all() return cls.list_to_dict(seltime_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_cidgreat(cls, cid): try: achi_li = Achievements.query.filter(Achievements.cid==cid, or_(Achievements.isgreat==0, Achievements.isgreat==1)) return cls.list_to_dict(achi_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_credit(cls, credit): try: course_li = Courses.query.filter_by(credit=credit) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_gradepoint(cls, gradepoint): try: achi_li = Achievements.query.filter_by(gradepoint=gradepoint) return cls.list_to_dict(achi_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_cid(cls, cid): try: achi_li = Achievements.query.filter_by(cid=cid, isgreat=-1) return cls.list_to_dict(achi_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_all(cls): try: campus_li = Campuses.query.all() return cls.list_to_dict(campus_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_id(cls, caid): try: campus_li = Campuses.query.get(caid) return cls.list_to_dict([campus_li])[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_rname(rid): try: room = Classrooms.query.get(rid) if room is not None: return str(room.rname) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return "error"
def get_by_credit(cls, credit): try: achi_li = Achievements.query.filter_by(credit=credit) return cls.list_to_dict(achi_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_cid_count(cid): count = 0 try: count = Achievements.query.filter_by(cid=cid).count() except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return count
def get_load_course(cls): """获取要加载缓存的课程""" try: course_li = Courses.query.filter_by(ispass=1, isexamine=1, isend=0) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_by_pass(cls, tid): """获取教师任教课程业务""" try: course_li = Courses.query.filter_by(tid=tid, ispass=1, isend=0) return cls.list_to_dict(course_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()
def get_can_add_to_redis(cls, caid): try: course_li = Courses.query.filter_by(caid=caid, isend=0, ispass=1, isexamine=1) return course_li except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_id(cls, cid): try: course = Courses.query.get(cid) if course is None: return course else: return cls.list_to_dict([course])[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_id(cls, acid): try: achi = Achievements.query.get(acid) if achi is None: return achi else: return cls.list_to_dict(achi)[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_id(cls, id): try: cosel = Selcourses.query.get(id) if cosel is None: return cosel else: return cls.list_to_dict(cosel)[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_id(cls, id): try: seltime = Coseltime.query.get(id) if seltime is None: return seltime else: return cls.list_to_dict(seltime)[0] except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return None
def get_by_sidnoend(cls, sid): try: cosel_li = Selcourses.query.filter_by(sid=sid) sel_li = list() for sel in cosel_li: if sel.course.isend == 0: sel_li.append(sel) return cls.list_to_dict(sel_li) except Exception as e: print(e) ExceptionLog.model_error(e.__str__()) return list()