本文整理汇总了Python中addons.osfstorage.models.OsfStorageFileNode.load方法的典型用法代码示例。如果您正苦于以下问题:Python OsfStorageFileNode.load方法的具体用法?Python OsfStorageFileNode.load怎么用?Python OsfStorageFileNode.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.osfstorage.models.OsfStorageFileNode
的用法示例。
在下文中一共展示了OsfStorageFileNode.load方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_file_no_guid
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_delete_file_no_guid(self):
child = self.node_settings.get_root().append_file('Test')
assert_is(OsfStorageFileNode.load(child._id).guids.first(), None)
with mock.patch('osf.models.files.apps.get_model') as get_model:
child.delete()
assert_is(get_model.called, False)
assert_is(OsfStorageFileNode.load(child._id), None)
示例2: test_delete_file_guids
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_delete_file_guids(self):
child = self.node_settings.get_root().append_file('Test')
guid = child.get_guid(create=True)
assert_is_not(OsfStorageFileNode.load(child._id).guids.first(), None)
with mock.patch('osf.models.files.apps.get_model') as get_model:
child.delete()
assert_is(get_model.called, True)
assert_is(get_model('osf.Comment').objects.filter.called, True)
assert_is(OsfStorageFileNode.load(child._id), None)
示例3: test_delete_folder
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_delete_folder(self):
parent = self.node_settings.get_root().append_folder('Test')
kids = []
for x in range(10):
kid = parent.append_file(str(x))
kid.save()
kids.append(kid)
count = OsfStorageFileNode.find().count()
tcount = models.TrashedFileNode.find().count()
parent.delete()
assert_is(OsfStorageFileNode.load(parent._id), None)
assert_equals(count - 11, OsfStorageFileNode.find().count())
assert_equals(tcount + 11, models.TrashedFileNode.find().count())
for kid in kids:
assert_is(
OsfStorageFileNode.load(kid._id),
None
)
示例4: test_delete
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_delete(self):
file = self.root_node.append_file('Newfile')
resp = self.delete(file)
assert_equal(resp.status_code, 200)
assert_equal(resp.json, {'status': 'success'})
fid = file._id
del file
# models.StoredFileNode._clear_object_cache()
assert_is(OsfStorageFileNode.load(fid), None)
assert_true(models.TrashedFileNode.load(fid))
示例5: test_create_with_parent
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_create_with_parent(self):
resp = self.create_folder('name')
assert_equal(resp.status_code, 201)
assert_equal(self.root_node.children.count(), 1)
assert_equal(self.root_node.children.all()[0].serialize(), resp.json['data'])
resp = self.create_folder('name', parent=OsfStorageFileNode.load(resp.json['data']['id']))
assert_equal(resp.status_code, 201)
assert_equal(self.root_node.children.count(), 1)
assert_false(self.root_node.children.all()[0].is_file)
assert_equal(self.root_node.children.all()[0].children.count(), 1)
assert_false(self.root_node.children.all()[0].children.all()[0].is_file)
assert_equal(self.root_node.children.all()[0].children.all()[0].serialize(), resp.json['data'])
示例6: test_delete_file
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def test_delete_file(self):
child = self.node_settings.get_root().append_file('Test')
field_names = [f.name for f in child._meta.get_fields() if not f.is_relation and f.name not in ['id', 'content_type_pk']]
child_data = {f: getattr(child, f) for f in field_names}
child.delete()
assert_is(OsfStorageFileNode.load(child._id), None)
trashed = models.TrashedFileNode.load(child._id)
child_storage = dict()
trashed_storage = dict()
trashed_storage['parent'] = trashed.parent._id
child_storage['materialized_path'] = child.materialized_path
assert_equal(trashed.path, '/' + child._id)
trashed_field_names = [f.name for f in child._meta.get_fields() if not f.is_relation and
f.name not in ['id', '_materialized_path', 'content_type_pk', '_path', 'deleted_on', 'deleted_by', 'type']]
for f, value in child_data.iteritems():
if f in trashed_field_names:
assert_equal(getattr(trashed, f), value)
示例7: welcome_osf4m
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def welcome_osf4m(email):
""" presend has two functions. First is to make sure that the user has not
converted to a regular OSF user by logging in. Second is to populate the
data field with downloads by finding the file/project (node_settings) and
counting downloads of all files within that project
:param email: QueuedMail object with data field including fid
:return: boolean based on whether the email should be sent
"""
# In line import to prevent circular importing
from addons.osfstorage.models import OsfStorageFileNode
if email.user.date_last_login:
if email.user.date_last_login > timezone.now() - settings.WELCOME_OSF4M_WAIT_TIME_GRACE:
return False
upload = OsfStorageFileNode.load(email.data['fid'])
if upload:
email.data['downloads'] = upload.get_download_count()
else:
email.data['downloads'] = 0
email.save()
return True
示例8: get_auth
# 需要导入模块: from addons.osfstorage.models import OsfStorageFileNode [as 别名]
# 或者: from addons.osfstorage.models.OsfStorageFileNode import load [as 别名]
def get_auth(auth, **kwargs):
cas_resp = None
if not auth.user:
# Central Authentication Server OAuth Bearer Token
authorization = request.headers.get('Authorization')
if authorization and authorization.startswith('Bearer '):
client = cas.get_client()
try:
access_token = cas.parse_auth_header(authorization)
cas_resp = client.profile(access_token)
except cas.CasError as err:
sentry.log_exception()
# NOTE: We assume that the request is an AJAX request
return json_renderer(err)
if cas_resp.authenticated:
auth.user = OSFUser.load(cas_resp.user)
try:
data = jwt.decode(
jwe.decrypt(request.args.get('payload', '').encode('utf-8'), WATERBUTLER_JWE_KEY),
settings.WATERBUTLER_JWT_SECRET,
options={'require_exp': True},
algorithm=settings.WATERBUTLER_JWT_ALGORITHM
)['data']
except (jwt.InvalidTokenError, KeyError) as err:
sentry.log_message(str(err))
raise HTTPError(httplib.FORBIDDEN)
if not auth.user:
auth.user = OSFUser.from_cookie(data.get('cookie', ''))
try:
action = data['action']
node_id = data['nid']
provider_name = data['provider']
except KeyError:
raise HTTPError(httplib.BAD_REQUEST)
node = AbstractNode.load(node_id) or Preprint.load(node_id)
if not node:
raise HTTPError(httplib.NOT_FOUND)
check_access(node, auth, action, cas_resp)
provider_settings = None
if hasattr(node, 'get_addon'):
provider_settings = node.get_addon(provider_name)
if not provider_settings:
raise HTTPError(httplib.BAD_REQUEST)
try:
path = data.get('path')
version = data.get('version')
credentials = None
waterbutler_settings = None
fileversion = None
if provider_name == 'osfstorage':
if path and version:
# check to see if this is a file or a folder
filenode = OsfStorageFileNode.load(path.strip('/'))
if filenode and filenode.is_file:
try:
fileversion = FileVersion.objects.filter(
basefilenode___id=path.strip('/'),
identifier=version
).select_related('region').get()
except FileVersion.DoesNotExist:
raise HTTPError(httplib.BAD_REQUEST)
# path and no version, use most recent version
elif path:
filenode = OsfStorageFileNode.load(path.strip('/'))
if filenode and filenode.is_file:
fileversion = FileVersion.objects.filter(
basefilenode=filenode
).select_related('region').order_by('-created').first()
if fileversion:
region = fileversion.region
credentials = region.waterbutler_credentials
waterbutler_settings = fileversion.serialize_waterbutler_settings(
node_id=provider_settings.owner._id if provider_settings else node._id,
root_id=provider_settings.root_node._id if provider_settings else node.root_folder._id,
)
# If they haven't been set by version region, use the NodeSettings region
if not (credentials and waterbutler_settings):
credentials = node.serialize_waterbutler_credentials(provider_name)
waterbutler_settings = node.serialize_waterbutler_settings(provider_name)
except exceptions.AddonError:
log_exception()
raise HTTPError(httplib.BAD_REQUEST)
# TODO: Add a signal here?
if waffle.switch_is_active(features.ELASTICSEARCH_METRICS):
user = auth.user
if isinstance(node, Preprint) and not node.is_contributor(user):
metric_class = get_metric_class_for_action(action)
if metric_class:
try:
metric_class.record_for_preprint(
preprint=node,
user=user,
version=fileversion.identifier if fileversion else None,
#.........这里部分代码省略.........