def update_supervisor(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = {} if query_dict is None: query_dict = {} query = Supervisor.query.filter(Supervisor.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Supervisor) (supervisors, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for supervisor in supervisors: for key, value in data.items(): if hasattr(supervisor, key): setattr(supervisor, key, value) db.session.add(supervisor) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def update_group(cls, ctx=True, query_dict: dict = None, data: dict = None): if data is None: data = {} if query_dict is None: query_dict = {} url_condition = UrlCondition(query_dict) query = Group.query.filter(Group.using == True) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Group) (groups, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for group in groups: for key, value in data.items(): if hasattr(group, key): setattr(group, key, value) db.session.add(group) if ctx: try: db.session.commit() except Exception as e: db.session.rollback() raise CustomError(500, 500, str(e)) return True
def query_teacher_names(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = NoticeLesson.query.with_entities( NoticeLesson.lesson_teacher_id, NoticeLesson.lesson_teacher_name, NoticeLesson.lesson_teacher_unit, NoticeLesson.lesson_attention_reason, NoticeLesson.group_name).distinct() if not unscoped: query = query.filter(NoticeLesson.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, NoticeLesson) (lessons, total) = page_query(query, url_condition.page_dict) print(lessons) except Exception as e: raise CustomError(500, 500, str(e)) return [{ 'lesson_teacher_name': data.lesson_teacher_name, 'lesson_teacher_id': data.lesson_teacher_id, 'lesson_teacher_unit': data.lesson_teacher_unit, 'lesson_attention_reason': data.lesson_attention_reason, 'group_name': data.group_name } for data in lessons], total
def update_lesson_record(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = dict() if query_dict is None: query_dict = dict() data = cls.reformatter_update(data) query = LessonRecord.query.filter(LessonRecord.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, LessonRecord) (lesson_records, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for lesson_record in lesson_records: for key, value in data.items(): if hasattr(lesson_record, key): setattr(lesson_record, key, value) db.session.add(lesson_record) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def query_lessons(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = Lesson.query if not unscoped: query = query.filter(Lesson.using == True) lesson_or_teacher_name = query_dict.get('lesson_or_teacher_name_or', None) if lesson_or_teacher_name is not None and len( lesson_or_teacher_name) != 0: del query_dict['lesson_or_teacher_name_or'] lesson_or_teacher_name = lesson_or_teacher_name[0] query = query.filter( or_( Lesson.lesson_name.like(lesson_or_teacher_name + "%"), Lesson.lesson_teacher_name.like(lesson_or_teacher_name + "%"))) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Lesson) (lessons, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(lesson) for lesson in lessons], total
def update_activity_user(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = {} if query_dict is None: query_dict = {} data = cls.reformatter_update(data) query = ActivityUser.query.filter(ActivityUser.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, ActivityUser) (activity_users, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for activity_user in activity_users: for key, value in data.items(): if hasattr(activity_user, key): setattr(activity_user, key, value) db.session.add(activity_user) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def update_model_lesson(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = {} if query_dict is None: query_dict = {} data = cls.reformatter_update(data) query = ModelLesson.query.filter(ModelLesson.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, ModelLesson) (model_lessons, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for model_lesson in model_lessons: for key, value in data.items(): if hasattr(model_lesson, key): setattr(model_lesson, key, value) db.session.add(model_lesson) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def update_consult_type(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = {} if query_dict is None: query_dict = {} data = cls.reformatter_update(data) query = ConsultType.query.filter(ConsultType.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, ConsultType) (consult_types, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for consult_type in consult_types: for key, value in data.items(): if hasattr(consult_type, key): setattr(consult_type, key, value) db.session.add(consult_type) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def update_work_plan(cls, ctx: bool = True, query_dict: dict = None, data: dict = None): if data is None: data = dict() if query_dict is None: query_dict = dict() data = cls.reformatter_update(data) query = WorkPlan.query.filter(WorkPlan.using == True) url_condition = mysql_url_condition.UrlCondition(query_dict) try: query = mysql_url_condition.process_query( query, url_condition.filter_dict, url_condition.sort_limit_dict, WorkPlan) (work_plans, total) = mysql_url_condition.page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for work_plan in work_plans: for key, value in data.items(): if hasattr(work_plan, key): setattr(work_plan, key, value) db.session.add(work_plan) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def query_supervisors(cls, query_dict: dict, unscoped: bool = False): query = Supervisor.query if not unscoped: query = query.filter(Supervisor.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Supervisor) (supervisors, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(supervisor) for supervisor in supervisors], total
def query_groups(cls, query_dict: dict = None): if query_dict is None: query_dict = {} url_condition = UrlCondition(query_dict) query = Group.query.filter(Group.using == True) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Group) (groups, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(data) for data in query], total
def get_model_lesson_by_lesson_id(cls, query_dict:dict, unscoped: bool = False): model_lesson = ModelLesson.query if not unscoped: model_lesson = model_lesson.filter(ModelLesson.using == True) url_condition = UrlCondition(query_dict) try: model_lesson = process_query(model_lesson, url_condition.filter_dict, url_condition.sort_limit_dict, ModelLesson).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(model_lesson)
def get_notice_lesson(cls, query_dict: dict, unscoped: bool = False): notice_lesson_teacher = NoticeLesson.query if not unscoped: notice_lesson_teacher = notice_lesson_teacher.filter(NoticeLesson.using == True) url_condition = UrlCondition(query_dict) try: notice_lesson_teacher = process_query(notice_lesson_teacher, url_condition.filter_dict, url_condition.sort_limit_dict, NoticeLesson).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(notice_lesson_teacher)
def get_lesson_case(cls, query_dict: dict, unscoped: bool = False): lesson_case = cls.query if not unscoped: lesson_case = lesson_case.filter(cls.using == True) url_condition = UrlCondition(query_dict) try: lesson_case = process_query(lesson_case, url_condition.filter_dict, url_condition.sort_limit_dict, cls).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(lesson_case)
def get_activity(cls, query_dict: dict, unscoped: bool = False): activity = Activity.query if not unscoped: activity = activity.filter(Activity.using == True) url_condition = UrlCondition(query_dict) try: activity = process_query(activity, url_condition.filter_dict, url_condition.sort_limit_dict, Activity).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(activity)
def get_supervisor_by_id(cls, query_dict: dict, unscoped: bool = False): supervisor = Supervisor.query if not unscoped: supervisor = supervisor.filter(Supervisor.using == True) url_condition = UrlCondition(query_dict) try: supervisor = process_query(supervisor, url_condition.filter_dict, url_condition.sort_limit_dict, Supervisor).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(supervisor)
def get_user(cls, query_dict: dict, unscoped=False): user = User.query if not unscoped: user = user.filter(User.using == True) url_condition = UrlCondition(query_dict) try: user = process_query(user, url_condition.filter_dict, url_condition.sort_limit_dict, User).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(user)
def get_event(cls, query_dict: dict, unscoped: bool = False): event = Event.query if not unscoped: event = event.filter(Event.using == True) url_condition = UrlCondition(query_dict) try: event = process_query(event, url_condition.filter_dict, url_condition.sort_limit_dict, Event).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(event)
def get_work_plan(cls, query_dict: dict, unscoped: bool = False): work_plan = WorkPlan.query if not unscoped: work_plan = work_plan.filter(WorkPlan.using == True) url_condition = mysql_url_condition.UrlCondition(query_dict) try: work_plan = mysql_url_condition.process_query( work_plan, url_condition.filter_dict, url_condition.sort_limit_dict, WorkPlan).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(work_plan)
def get_consult(cls, query_dict: dict, unscoped: bool = False): consult = Consult.query if not unscoped: consult = consult.filter(Consult.using == True) url_condition = UrlCondition(query_dict) try: consult = process_query(consult, url_condition.filter_dict, url_condition.sort_limit_dict, Consult).first() except Exception as e: raise CustomError(500, 500, str(e)) return cls.formatter(consult)
def query_activities(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = Activity.query if not unscoped: query = query.filter(Activity.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Activity) (activities, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(activity) for activity in activities], total
def query_teacher_names(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = Lesson.query.with_entities(Lesson.lesson_teacher_name).distinct() if not unscoped: query = query.filter(Lesson.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Lesson) (lessons, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [data.lesson_teacher_name for data in query], total
def query_lesson_cases(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = cls.query if not unscoped: query = query.filter(cls.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, cls) (lesson_cases, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(lesson_case) for lesson_case in lesson_cases], total
def query_other_model_lessons(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = OtherModelLesson.query if not unscoped: query = query.filter(OtherModelLesson.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, OtherModelLesson) (other_model_lessons, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(other_model_lesson) for other_model_lesson in other_model_lessons], total
def query_users(cls, query_dict: dict = None, unscoped=False): if query_dict is None: query_dict = {} query = User.query if not unscoped: query = query.filter(User.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, User) (users, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(user) for user in users], total
def query_events(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = {} query = Event.query if not unscoped: query = query.filter(Event.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Event) (events, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(event) for event in events], total
def query_terms(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = dict() url_condition = UrlCondition(query_dict) query = Term.query if not unscoped: query = query.filter(Term.using == True) if 'time' in query_dict: query = query.filter(Term.begin_time < query_dict['time']).filter( Term.end_time >= query_dict['time']) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Term) (terms, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(term) for term in terms], total
def query_work_plan(cls, query_dict: dict = None, unscoped: bool = False): if query_dict is None: query_dict = dict() query = WorkPlan.query if not unscoped: query = query.filter(WorkPlan.using == True) url_condition = mysql_url_condition.UrlCondition(query_dict) try: query = mysql_url_condition.process_query( query, url_condition.filter_dict, url_condition.sort_limit_dict, WorkPlan) (res, total) = mysql_url_condition.page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) return [cls.formatter(data) for data in res], total
def delete_event(cls, ctx: bool = True, query_dict: dict = None): if query_dict is None: query_dict = {} query = Event.query.filter(Event.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Event) (events, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for event in events: event.using = False db.session.add(event) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True
def delete_supervisor(cls, ctx: bool = True, query_dict: dict = None): if query_dict is None: query_dict = {} query = Supervisor.query.filter(Supervisor.using == True) url_condition = UrlCondition(query_dict) try: query = process_query(query, url_condition.filter_dict, url_condition.sort_limit_dict, Supervisor) (supervisors, total) = page_query(query, url_condition.page_dict) except Exception as e: raise CustomError(500, 500, str(e)) for supervisor in supervisors: supervisor.using = False db.session.add(supervisor) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True