예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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
예제 #4
0
 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
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 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
예제 #9
0
 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
예제 #10
0
 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
예제 #11
0
 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
예제 #12
0
 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)
예제 #13
0
 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)
예제 #14
0
 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)
예제 #15
0
 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)
예제 #16
0
 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)
예제 #17
0
 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)
예제 #18
0
 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)
예제 #19
0
 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)
예제 #20
0
 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)
예제 #21
0
 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
예제 #22
0
 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
예제 #23
0
 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
예제 #24
0
 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
예제 #25
0
 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
예제 #26
0
 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
예제 #27
0
 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
예제 #28
0
 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
예제 #29
0
 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
예제 #30
0
 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