def _panels_batch_crud(self, panel_schema, panels): schema_instance = panel_schema() # 删除panels saved_panels = [] for panel in panels: one_panel, errors = schema_instance.load(panel) if errors: raise Exception(errors) if panel.get('status') == -1: # 删除对应的panel try: one_panel.delete() except InvalidRequestError: pass else: # 新增和修改对应的panel one_panel.save() panel_filters = panel.get('filters', []) for filter in panel_filters: filter['belong_id'] = one_panel.id filter['bussiness_id'] = g.bussiness_id filter['page_id'] = one_panel.page_id panel_filters = common_batch_crud(FilterSchema, FiltersModel, panel_filters) panel, errors = panel_schema( exclude=PanelsModel.column_filter).dump(one_panel) panel['filters'] = panel_filters saved_panels.append(panel) return saved_panels
def put(self, bussiness_id): input_json = request.get_json() for database in input_json: database['bussiness_id'] = bussiness_id databases = common_batch_crud(DatabasesSchema, DatabasesModel, input_json) return self.response_json(self.HttpErrorCode.SUCCESS, data=databases)
def post(self): """ POST """ input_json = request.get_json() schema = self.schema_class() bussiness, errors = schema.load(input_json) if errors: return self.response_json(self.HttpErrorCode.PARAMS_VALID_ERROR, msg=errors) bussiness.save() # 管理员增改删 managers = input_json.get('managers', []) for manager in managers: manager['bussiness_id'] = bussiness.id common_batch_crud(BManagerSchema, BManagerModel, managers) return self.response_json(self.HttpErrorCode.SUCCESS, data={'bussiness_id': bussiness.id})
def put(self, page_id): input_data = request.get_json() global_filters, panels = input_data['global_filters'], input_data['panels'] for global_filter in global_filters: global_filter['bussiness_id'] = g.bussiness_id global_filters = common_batch_crud(FilterSchema, FiltersModel, global_filters) panels = self._panels_batch_crud(PanelSchema, panels) data = {'global_filters': global_filters, 'panels': panels} return self.response_json(self.HttpErrorCode.SUCCESS, data=data)