helpers.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mist.api 作者: mistio 项目源码 文件源码
def get_object_with_id(owner, rid, rtype, *args, **kwargs):
    query = {}
    if rtype in ['machine', 'network', 'image', 'location']:
        if 'cloud_id' not in kwargs:
            raise RequiredParameterMissingError('No cloud id provided')
        else:
            query.update({'cloud': kwargs['cloud_id']})
    if rtype == 'machine':
        query.update({'machine_id': rid})
    else:
        query.update({'id': rid, 'deleted': None})

    if rtype not in ['machine', 'image']:
        query.update({'owner': owner})

    try:
        resource_obj = get_resource_model(rtype).objects.get(**query)
    except DoesNotExist:
        raise NotFoundError('Resource with this id could not be located')

    return resource_obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号