def put(self, args, mould_id): layer_id = args.get('layer_id', None) if layer_id and not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) mould = self.record if not args: error(InterfaceTips.NO_PARAMS) if Mould.existed_record(mould, code=args.get('code'), name=args.get('name')): error(InterfaceTips.RECORD_HAS_EXISTED) aggregation_id = args.pop('aggregation_id', None) if aggregation_id: aggregation = Aggregation.find_by_pk(aggregation_id) if aggregation: args.update({'aggregation': aggregation}) else: error(InterfaceTips.AGGREGATION_NOT_EXISTED) parent_id = args.pop('parent_id', None) if parent_id: parent = Mould.find_by_pk(parent_id) if not parent: error(InterfaceTips.PARENT_DATA_NOT_EXISTED) else: args.update({'parent': parent}) mould = mould.update(**args) children = mould_schema.dump(mould).data return children
def post(self, args, layer_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) if Aggregation.existed_record(code=args.get('code'), name=args.get('name')): error(InterfaceTips.RECORD_HAS_EXISTED) args.update(layer_id=layer_id) aggregation = Aggregation.create(**args) return aggregation_schema.dump(aggregation).data, 201
def put(self, args, aggregation_id): layer_id = args.get('layer_id', None) if layer_id and not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) aggregation = self.record if Aggregation.existed_record(aggregation, code=args.get('code'), name=args.get('name')): error(InterfaceTips.RECORD_HAS_EXISTED) aggregation = aggregation.update(**args) return aggregation_schema.dump(aggregation).data
def get(self, layer_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) aggregations, total = Aggregation.pagination(layer_id=layer_id) result = [] for aggregation in aggregations: aggregation_data = aggregation_schema.dump(aggregation).data moulds = Mould.fetch_all(aggregation=aggregation) aggregation_data.update( {'moulds': moulds_base_schema.dump(moulds).data}) result.append(aggregation_data) return result
def get(self, args, layer_id, aggregation_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) aggregation = self.record page = args.get('page', 1) per_page = args.get('per_page', 20) moulds, total = Mould.pagination(page, per_page, layer_id=layer_id, aggregation=aggregation) return BaseResource.pagination( moulds_schema.dump(moulds).data, total, per_page)
def get(self, layer_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) instances = Instance.get_ancestors(layer_id) children = instance_nodes_schema.dump(instances).data layer_data = LAYERS_CONFIG.get(layer_id) instance_info = layer_data.get('instance_info') if children: instance_info.update({ 'has_children': bool(children), 'children': children }) return instance_info
def get(self, layer_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) moulds = Mould.get_ancestors(layer_id) children = mould_nodes_schema.dump(moulds).data layer_data = LAYERS_CONFIG.get(layer_id) mould_info = layer_data.get('mould_info') if children: mould_info.update({ 'has_children': bool(children), 'children': children }) return mould_info
def post(self, args, layer_id, aggregation_id): if not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) aggregation = self.record if Mould.existed_record(code=args.get('code'), name=args.get('name')): error(InterfaceTips.RECORD_HAS_EXISTED) parent_id = args.pop('parent_id', None) if parent_id: parent = Mould.find_by_pk(parent_id) if not parent: error(InterfaceTips.PARENT_DATA_NOT_EXISTED) else: args.update({'parent': parent}) args.update({'aggregation': aggregation, 'layer_id': layer_id}) mould = Mould.create(**args) return mould_schema.dump(mould).data, 201
def put(self, args, instance_id): layer_id = args.get('layer_id', None) if layer_id and not validate_valid_layer_id(layer_id): error(InterfaceTips.INVALID_LAYER_ID) instance = self.record success, error_message = instance.mould.validate_abilities( args.get('abilities', {})) if not success: return error_message, 422 parent_id = args.pop('parent_id', None) if instance.mould.parent: if parent_id: parent = Instance.find_by_pk(parent_id) if not parent: error(InterfaceTips.PARENT_DATA_NOT_EXISTED) args.update({'parent': parent}) else: error(InterfaceTips.PARENT_ID_IS_REQUIRED) # if Mould.existed_record(instance, **args): # error(InterfaceTips.RECORD_HAS_EXISTED) instance = instance.update(**args) return instance_detail_schema.dump(instance).data