本文整理汇总了Python中osf.models.Guid.load方法的典型用法代码示例。如果您正苦于以下问题:Python Guid.load方法的具体用法?Python Guid.load怎么用?Python Guid.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf.models.Guid
的用法示例。
在下文中一共展示了Guid.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reverse_func
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def reverse_func(state, schema):
"""
Reverses NodeWikiPage migration. Repoints guids back to each NodeWikiPage,
repoints comment_targets, comments_viewed_timestamps, and deletes all WikiVersions and WikiPages
"""
nwp_content_type_id = ContentType.objects.get_for_model(NodeWikiPage).id
nodes = AbstractNode.objects.exclude(wiki_pages_versions={})
progress_bar = progressbar.ProgressBar(maxval=nodes.count() or 100).start()
for i, node in enumerate(nodes, 1):
progress_bar.update(i)
for wiki_key, version_list in node.wiki_pages_versions.iteritems():
if version_list:
for index, version in enumerate(version_list):
nwp = NodeWikiPage.objects.filter(former_guid=version).include(None)[0]
# All NodeWikiPages associated with a certain wiki key on a node point to the same WikiPage.
wp = WikiPage.load(version)
guid = migrate_guid_referent(Guid.load(version), nwp, nwp_content_type_id)
guid.save()
nwp = guid.referent
# Moved only for last item in wiki_pages_versions array for every page_name, NWP->WP is a many-to-one mapping. NWP->WV is a one-to-one mapping.
move_comment_target(Guid.load(wp._id), nwp)
update_comments_viewed_timestamp(node, wp._id, nwp)
progress_bar.finish()
WikiVersion.objects.all().delete()
WikiPage.objects.all().delete()
logger.info('NodeWikiPages restored and WikiVersions and WikiPages removed.')
示例2: update_file_guid_referent
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def update_file_guid_referent(self, node, event_type, payload, user=None):
if event_type not in ('addon_file_moved', 'addon_file_renamed'):
return # Nothing to do
source, destination = payload['source'], payload['destination']
source_node, destination_node = Node.load(source['node']['_id']), Node.load(destination['node']['_id'])
if source['provider'] in settings.ADDONS_BASED_ON_IDS:
if event_type == 'addon_file_renamed':
return # Node has not changed and provider has not changed
# Must be a move
if source['provider'] == destination['provider'] and source_node == destination_node:
return # Node has not changed and provider has not changed
file_guids = BaseFileNode.resolve_class(source['provider'], BaseFileNode.ANY).get_file_guids(
materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
provider=source['provider'],
node=source_node
)
for guid in file_guids:
obj = Guid.load(guid)
if source_node != destination_node and Comment.find(Q('root_target._id', 'eq', guid)).count() != 0:
update_comment_node(guid, source_node, destination_node)
if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
old_file = BaseFileNode.load(obj.referent._id)
obj.referent = create_new_file(obj, source, destination, destination_node)
obj.save()
if old_file and not TrashedFileNode.load(old_file._id):
old_file.delete()
示例3: get_paginated_response
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def get_paginated_response(self, data):
"""Add number of unread comments to links.meta when viewing list of comments filtered by
a target node, file or wiki page."""
response = super(CommentPagination, self).get_paginated_response(data)
response_dict = response.data
kwargs = self.request.parser_context['kwargs'].copy()
if self.request.query_params.get('related_counts', False):
target_id = self.request.query_params.get('filter[target]', None)
node_id = kwargs.get('node_id', None)
node = Node.load(node_id)
user = self.request.user
if target_id and not user.is_anonymous and node.is_contributor(user):
root_target = Guid.load(target_id)
if root_target:
page = getattr(root_target.referent, 'root_target_page', None)
if page:
if not len(data):
unread = 0
else:
unread = Comment.find_n_unread(user=user, node=node, page=page, root_id=target_id)
if self.request.version < '2.1':
response_dict['links']['meta']['unread'] = unread
else:
response_dict['meta']['unread'] = unread
return Response(response_dict)
示例4: test_update_wiki_updates_contributor_comments_viewed_timestamp
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_update_wiki_updates_contributor_comments_viewed_timestamp(self):
contributor = AuthUserFactory()
project = ProjectFactory(creator=self.user, is_public=True)
project.add_contributor(contributor)
project.save()
wiki_page = WikiFactory(node=project, page_name='test')
wiki = WikiVersionFactory(wiki_page=wiki_page)
comment = CommentFactory(node=project, target=Guid.load(wiki_page._id), user=self.user)
# user views comments -- sets user.comments_viewed_timestamp
url = project.api_url_for('update_comments_timestamp')
res = self.app.put_json(url, {
'page': 'wiki',
'rootId': wiki_page._id
}, auth=self.user.auth)
assert res.status_code == 200
self.user.reload()
assert wiki_page._id in self.user.comments_viewed_timestamp
# contributor views comments -- sets contributor.comments_viewed_timestamp
res = self.app.put_json(url, {
'page': 'wiki',
'rootId': wiki_page._id
}, auth=contributor.auth)
contributor.reload()
assert wiki_page._id in contributor.comments_viewed_timestamp
# user updates the wiki
project.update_node_wiki('test', 'Updating wiki', self.auth)
comment.reload()
contributor.reload()
new_version_id = project.get_wiki_version('test')._id
assert wiki_page._id in contributor.comments_viewed_timestamp
assert comment.target.referent._id == wiki_page._id
示例5: public_comment_reply
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def public_comment_reply(self, user, public_comment, public_project):
reply_target = Guid.load(public_comment._id)
return CommentFactory(
node=public_project,
target=reply_target,
user=user
)
示例6: persistent_file_download
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def persistent_file_download(auth, **kwargs):
id_or_guid = kwargs.get('fid_or_guid')
file = BaseFileNode.active.filter(_id=id_or_guid).first()
if not file:
guid = Guid.load(id_or_guid)
if guid:
file = guid.referent
else:
raise HTTPError(httplib.NOT_FOUND, data={
'message_short': 'File Not Found',
'message_long': 'The requested file could not be found.'
})
if not file.is_file:
raise HTTPError(httplib.BAD_REQUEST, data={
'message_long': 'Downloading folders is not permitted.'
})
auth_redirect = check_contributor_auth(file.target, auth,
include_public=True,
include_view_only_anon=True)
if auth_redirect:
return auth_redirect
query_params = request.args.to_dict()
return redirect(
file.generate_waterbutler_url(**query_params),
code=httplib.FOUND
)
示例7: get_target
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def get_target(self, target_id):
guid = Guid.load(target_id)
if not guid:
raise NotFound
target = guid.referent
if getattr(target, 'is_registration', False) and not getattr(target, 'archiving', False):
raise ValidationError('Registrations cannot be changed.')
return target
示例8: test_find_unread_includes_comment_replies
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_find_unread_includes_comment_replies(self):
project = ProjectFactory()
user = UserFactory()
project.add_contributor(user, save=True)
comment = CommentFactory(node=project, user=user)
CommentFactory(node=project, target=Guid.load(comment._id), user=project.creator)
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 1
示例9: get_redirect_url
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def get_redirect_url(self, **kwargs):
guid = Guid.load(kwargs['guids'])
if guid:
referent = guid.referent
if getattr(referent, 'absolute_api_v2_url', None):
return referent.absolute_api_v2_url
else:
raise EndpointNotImplementedError()
return None
示例10: test_wiki_has_comments_link
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_wiki_has_comments_link(self):
self._set_up_public_project_with_wiki_page()
res = self.app.get(self.public_url)
assert_equal(res.status_code, 200)
url = res.json['data']['relationships']['comments']['links']['related']['href']
comment = CommentFactory(node=self.public_project, target=Guid.load(self.public_wiki._id), user=self.user)
res = self.app.get(url)
assert_equal(res.status_code, 200)
assert_equal(res.json['data'][0]['type'], 'comments')
示例11: test_referent_can_be_set
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_referent_can_be_set(self, Factory):
obj = Factory()
obj1 = Factory()
guid = Guid.load(obj._id)
assert guid.referent == obj # sanity check
guid.referent = obj1
assert guid.referent == obj1
示例12: get_target
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def get_target(self, node_id, target_id):
target = Guid.load(target_id)
if not target or not getattr(target.referent, 'belongs_to_node', None):
raise ValueError('Invalid comment target.')
elif not target.referent.belongs_to_node(node_id):
raise ValueError('Cannot post to comment target on another node.')
elif isinstance(target.referent, BaseFileNode) and target.referent.provider not in osf_settings.ADDONS_COMMENTABLE:
raise ValueError('Comments are not supported for this file provider.')
return target
示例13: registration_comment_reply
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def registration_comment_reply(
self, user, registration,
registration_comment
):
reply_target = Guid.load(registration_comment._id)
return CommentFactory(
node=registration,
target=reply_target, user=user
)
示例14: test_resolve_guid_no_referent
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_resolve_guid_no_referent(self):
guid = Guid.load(self.node._id)
guid.referent = None
guid.save()
res = self.app.get(
self.node.web_url_for('node_setting', _guid=True),
auth=self.node.creator.auth,
expect_errors=True,
)
assert res.status_code == 404
示例15: test_private_node_only_logged_in_contributor_commenter_can_delete_own_reply
# 需要导入模块: from osf.models import Guid [as 别名]
# 或者: from osf.models.Guid import load [as 别名]
def test_private_node_only_logged_in_contributor_commenter_can_delete_own_reply(
self, app, user, private_project, comment):
reply_target = Guid.load(comment._id)
reply = CommentFactory(
node=private_project,
target=reply_target, user=user
)
reply_url = '/{}comments/{}/'.format(API_BASE, reply._id)
res = app.delete_json_api(reply_url, auth=user.auth)
assert res.status_code == 204