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 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 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_work_plan(cls, ctx: bool = True, query_dict: dict = None): if query_dict is None: query_dict = dict() 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: work_plan.using = False db.session.add(work_plan) if ctx: try: db.session.commit() except Exception as e: raise CustomError(500, 500, str(e)) return True