示例#1
0
    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
示例#4
0
    def post(self, args):
        user = User.get_user_by_email(args.get('email'))
        if not user:
            error(InterfaceTips.USER_NOT_EXISTED_OR_WRONG_PASSWORD)

        if not user.verify_password(args.get('password')):
            error(InterfaceTips.USER_NOT_EXISTED_OR_WRONG_PASSWORD)

        user_data = user_schema.dump(user).data
        user_data.update({'authentication_token': user.get_auth_token()})

        return user_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
示例#6
0
 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)
示例#7
0
 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
示例#8
0
 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
示例#9
0
    def post(self, args, mould_id):
        mould = self.record
        success, error_message = mould.validate_abilities(
            args.get('abilities', {}))
        if not success:
            return error_message, 422

        parent_id = args.pop('parent_id', None)
        if 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)

        # TODO check record is existed
        # if Mould.existed_record(**args):
        #     error(InterfaceTips.RECORD_HAS_EXISTED)

        instance = Instance.create(mould=mould, **args)
        return instance_detail_schema.dump(instance).data, 201
示例#10
0
 def wrapper(*args, **kwargs):
     record_id = kwargs.get(model_key, None)
     message = model_message if model_message else str(model)
     if record_id is None:
         error(InterfaceTips.DATA_NOT_EXISTED, {'model': message})
     try:
         record = model.find_by_pk(record_id)
     except Exception as e:
         error(InterfaceTips.DATA_NOT_EXISTED, {'model': message})
     else:
         if record is None:
             error(InterfaceTips.DATA_NOT_EXISTED,
                   {'model': message})
         cls.record = record
     return func(*args, **kwargs)
示例#11
0
    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
示例#12
0
    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
示例#13
0
 def unauthorized_handler():
     error(InterfaceTips.INVALID_TOKEN)