本文整理汇总了Python中addons.osfstorage.models.OsfStorageFileNode.get方法的典型用法代码示例。如果您正苦于以下问题:Python OsfStorageFileNode.get方法的具体用法?Python OsfStorageFileNode.get怎么用?Python OsfStorageFileNode.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.osfstorage.models.OsfStorageFileNode
的用法示例。
在下文中一共展示了OsfStorageFileNode.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapped
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import get [as 别名]
def wrapped(*args, **kwargs):
if 'fid' not in kwargs and default_root:
file_node = OsfStorageFolder.objects.get_root(kwargs['target'])
else:
file_node = OsfStorageFileNode.get(kwargs.get('fid'), kwargs['target'])
if must_be and file_node.kind != must_be:
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'incorrect type',
'message_long': 'FileNode must be of type {} not {}'.format(must_be, file_node.kind)
})
kwargs['file_node'] = file_node
return func(*args, **kwargs)
示例2: wrapped
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import get [as 别名]
def wrapped(payload, *args, **kwargs):
try:
user = OSFUser.load(payload['user'])
dest_node = AbstractNode.load(payload['destination']['node'])
source = OsfStorageFileNode.get(payload['source'], kwargs['node'])
dest_parent = OsfStorageFolder.get(payload['destination']['parent'], dest_node)
kwargs.update({
'user': user,
'source': source,
'destination': dest_parent,
'name': payload['destination']['name'],
})
except KeyError:
raise HTTPError(httplib.BAD_REQUEST)
return func(*args, **kwargs)
示例3: post
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import get [as 别名]
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data, context=self.get_serializer_context())
if serializer.is_valid():
source = serializer.validated_data.pop('source')
destination = serializer.validated_data.pop('destination')
name = destination.get('name')
dest_target = self.get_target(target_id=destination.get('target'))
try:
source = OsfStorageFileNode.get(source, self.get_object())
except OsfStorageFileNode.DoesNotExist:
raise NotFound
try:
dest_parent = OsfStorageFolder.get(destination.get('parent'), dest_target)
except OsfStorageFolder.DoesNotExist:
raise NotFound
serializer.save(source=source, destination=dest_parent, name=name)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)