本文整理汇总了Python中framework.guid.model.Guid类的典型用法代码示例。如果您正苦于以下问题:Python Guid类的具体用法?Python Guid怎么用?Python Guid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Guid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_targets_referent_is_none
def test_get_targets_referent_is_none(self):
bad_guid = Guid(referent=None)
bad_guid.save()
targets = list(get_targets())
assert_in(bad_guid, targets)
assert_not_in(self.nontarget_guid, targets)
示例2: _set_up_registration_with_comment
def _set_up_registration_with_comment(self):
self.registration = RegistrationFactory(creator=self.user, comment_level='private')
self.registration_wiki = NodeWikiFactory(node=self.registration, user=self.user)
self.registration_comment = CommentFactory(node=self.registration, target=Guid.load(self.registration_wiki._id), user=self.user)
self.comment_url = '/{}comments/{}/'.format(API_BASE, self.registration_comment._id)
reply_target = Guid.load(self.registration_comment._id)
self.registration_comment_reply = CommentFactory(node=self.registration, target=reply_target, user=self.user)
示例3: TestFindGuidsWithoutReferents
class TestFindGuidsWithoutReferents(OsfTestCase):
def setUp(self):
super(TestFindGuidsWithoutReferents, self).setUp()
self.node = NodeFactory()
self.nontarget_guid= Guid(referent=self.node)
self.nontarget_guid.save()
def test_get_targets_referent_is_none(self):
bad_guid = Guid(referent=None)
bad_guid.save()
targets = list(get_targets())
assert_in(bad_guid, targets)
assert_not_in(self.nontarget_guid, targets)
def test_get_targets_referent_points_to_nothing(self):
node = NodeFactory()
bad_guid = Guid(referent=node)
bad_guid.save()
Node.remove(Q('_id', 'eq', node._id))
targets = list(get_targets())
assert_in(bad_guid, targets)
assert_not_in(self.nontarget_guid, targets)
示例4: test_migrate_project_comment_reply
def test_migrate_project_comment_reply(self):
comment = self._set_up_comment_with_target(root_target=self.project, target=self.project)
reply = self._set_up_comment_with_target(root_target=self.project, target=comment)
update_comment_targets_to_guids()
reply.reload()
assert_equal(reply.root_target, Guid.load(self.project._id))
assert_equal(reply.target, Guid.load(comment._id))
示例5: test_get_targets_referent_points_to_nothing
def test_get_targets_referent_points_to_nothing(self):
node = NodeFactory()
bad_guid = Guid(referent=node)
bad_guid.save()
Node.remove(Q('_id', 'eq', node._id))
targets = list(get_targets())
assert_in(bad_guid, targets)
assert_not_in(self.nontarget_guid, targets)
示例6: _set_up_public_project_with_comment
def _set_up_public_project_with_comment(self):
self.public_project = ProjectFactory.create(is_public=True, creator=self.user, comment_level='private')
self.public_project.add_contributor(self.contributor, save=True)
self.public_wiki = NodeWikiFactory(node=self.public_project, user=self.user)
self.public_comment = CommentFactory(node=self.public_project, target=Guid.load(self.public_wiki._id), user=self.user)
reply_target = Guid.load(self.public_comment._id)
self.public_comment_reply = CommentFactory(node=self.public_project, target=reply_target, user=self.user)
self.public_url = '/{}comments/{}/'.format(API_BASE, self.public_comment._id)
self.public_comment_payload = self._set_up_payload(self.public_comment._id)
示例7: get_guid
def get_guid(self, create=False):
"""Attempt to find a Guid that points to this object.
One will be created if requested.
:rtype: Guid
"""
try:
# Note sometimes multiple GUIDs can exist for
# a single object. Just go with the first one
return Guid.find(Q('referent', 'eq', self))[0]
except IndexError:
if not create:
return None
return Guid.generate(self)
示例8: get_guid
def get_guid(self, create=False):
"""Attempt to find a Guid that points to this object.
One will be created if requested.
:param Boolean create: Should we generate a GUID if there isn't one? Default: False
:rtype: Guid or None
"""
try:
# Note sometimes multiple GUIDs can exist for
# a single object. Just go with the first one
return Guid.find(Q("referent", "eq", self))[0]
except IndexError:
if not create:
return None
return Guid.generate(self)
示例9: main
def main():
modm_guids = MODMGuid.find()
print 'MODM Guids: {}'.format(len(modm_guids))
guids = Guid.objects.filter(guid__in=modm_guids.get_keys())
filtered_count = len(guids)
total_count = Guid.objects.count()
if len(modm_guids) == filtered_count == total_count:
print 'Guids verified!'
else:
print 'Guids not verified!'
print 'Postgres Guids: {}'.format(Guid.objects.count())
guids = modm_guids = filtered_count = total_count = None
gc.collect()
modm_blacklist_guids = MODMBlacklistGuid.find()
print 'MODM BlacklistGuids: {}'.format(len(modm_blacklist_guids))
blacklist_guids = BlackListGuid.objects.filter(guid__in=modm_blacklist_guids.get_keys())
filtered_count = len(blacklist_guids)
total_count = BlackListGuid.objects.count()
if len(modm_blacklist_guids) == filtered_count == total_count:
print 'Blacklist Guids Verified!'
else:
print 'Blacklist Guids Not Verified!'
print 'Postgres Blacklist Guids: {}'.format(BlackListGuid.objects.count())
blacklist_guids = modm_blacklist_guids = filtered_count = total_count = None
gc.collect()
示例10: test_public_node_non_contributor_commenter_can_delete_wiki_comment
def test_public_node_non_contributor_commenter_can_delete_wiki_comment(self):
project = ProjectFactory(is_public=True, comment_level='public')
test_wiki = NodeWikiFactory(node=project, user=self.user)
comment = CommentFactory(node=project, target=Guid.load(test_wiki), user=self.non_contributor)
url = '/{}comments/{}/'.format(API_BASE, comment._id)
res = self.app.delete_json_api(url, auth=self.non_contributor.auth)
assert_equal(res.status_code, 204)
示例11: migrate_guids
def migrate_guids(guid_type, provider):
cls = models.FileNode.resolve_class(provider, models.FileNode.FILE)
for guid in paginated(guid_type):
# Note: No metadata is populated here
# It will be populated whenever this guid is next viewed
if guid.node is None:
logger.warning('{}({})\'s node is None; skipping'.format(guid_type, guid._id))
continue
if guid.waterbutler_path in ('/{{ revision.osfDownloadUrl }}', '/{{ currentVersion().osfDownloadUrl }}', '/{{ currentVersion().osfDownloadUrl }}', '/{{ node.urls.files }}', '/{{ revision.extra.user.url }}'):
logger.warning('{}({})\'s is a googlebot path; skipping'.format(guid_type, guid._id))
continue
logger.debug('Migrating guid {} ({})'.format(guid._id, guid.waterbutler_path))
try:
file_node = cls(
node=guid.node,
path=guid.waterbutler_path,
name=guid.waterbutler_path,
materialized_path=guid.waterbutler_path,
)
file_node.save()
except exceptions.KeyExistsException:
file_node = cls.find_one(
Q('node', 'eq', guid.node) &
Q('path', 'eq', guid.waterbutler_path)
)
logger.warning('{!r}({}) has multiple guids'.format(file_node.wrapped(), guid._id))
actual_guid = Guid.load(guid._id)
actual_guid.referent = file_node
actual_guid.save()
示例12: test_private_node_only_logged_in_contributor_commenter_can_delete_own_reply
def test_private_node_only_logged_in_contributor_commenter_can_delete_own_reply(self):
self._set_up_private_project_with_comment()
reply_target = Guid.load(self.comment._id)
reply = CommentFactory(node=self.private_project, target=reply_target, user=self.user)
reply_url = '/{}comments/{}/'.format(API_BASE, reply)
res = self.app.delete_json_api(reply_url, auth=self.user.auth)
assert_equal(res.status_code, 204)
示例13: restore
def restore(self, recursive=True, parent=None):
"""Recreate a StoredFileNode from the data in this object
Will re-point all guids and finally remove itself
:raises KeyExistsException:
"""
data = self.to_storage()
data.pop('deleted_on')
data.pop('deleted_by')
data.pop('suspended')
if parent:
data['parent'] = parent._id
elif data['parent']:
# parent is an AbstractForeignField, so it gets stored as tuple
data['parent'] = data['parent'][0]
restored = FileNode.resolve_class(self.provider, int(self.is_file))(**data)
if not restored.parent:
raise ValueError('No parent to restore to')
restored.save()
# repoint guid
for guid in Guid.find(Q('referent', 'eq', self)):
guid.referent = restored
guid.save()
if recursive:
for child in TrashedFileNode.find(Q('parent', 'eq', self)):
child.restore(recursive=recursive, parent=restored)
TrashedFileNode.remove_one(self)
return restored
示例14: update_file_guid_referent
def update_file_guid_referent(self, node, event_type, payload, user=None):
if event_type == 'addon_file_moved' or event_type == 'addon_file_renamed':
source = payload['source']
destination = payload['destination']
source_node = Node.load(source['node']['_id'])
destination_node = node
file_guids = FileNode.resolve_class(source['provider'], FileNode.ANY).get_file_guids(
materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
provider=source['provider'],
node=source_node)
if event_type == 'addon_file_renamed' and source['provider'] in settings.ADDONS_BASED_ON_IDS:
return
if event_type == 'addon_file_moved' and (source['provider'] == destination['provider'] and
source['provider'] in settings.ADDONS_BASED_ON_IDS) and source_node == destination_node:
return
for guid in file_guids:
obj = Guid.load(guid)
if source_node != destination_node and Comment.find(Q('root_target', 'eq', guid)).count() != 0:
update_comment_node(guid, source_node, destination_node)
if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
old_file = FileNode.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()
示例15: get_paginated_response
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)