本文整理汇总了Python中website.models.Node.load方法的典型用法代码示例。如果您正苦于以下问题:Python Node.load方法的具体用法?Python Node.load怎么用?Python Node.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.models.Node
的用法示例。
在下文中一共展示了Node.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _kwargs_to_nodes
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def _kwargs_to_nodes(kwargs):
"""Retrieve project and component objects from keyword arguments.
:param dict kwargs: Dictionary of keyword arguments
:return: Tuple of project and component
"""
project = kwargs.get('project') or Node.load(kwargs.get('pid', kwargs.get('nid')))
if not project:
raise HTTPError(http.NOT_FOUND)
if project.category != 'project':
raise HTTPError(http.BAD_REQUEST)
if project.is_deleted:
raise HTTPError(http.GONE)
if kwargs.get('nid') or kwargs.get('node'):
node = kwargs.get('node') or Node.load(kwargs.get('nid'))
if not node:
raise HTTPError(http.NOT_FOUND)
if node.is_deleted:
raise HTTPError(http.GONE)
else:
node = None
return project, node
示例2: add_hook_to_old_node_settings
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def add_hook_to_old_node_settings(document, account):
connect = GitHubClient(external_account=account)
secret = make_hook_secret()
hook = None
try:
hook = connect.add_hook(
document['user'], document['repo'],
'web',
{
'url': urlparse.urljoin(
HOOK_DOMAIN,
os.path.join(
Node.load(document['owner']).api_url, 'github', 'hook/'
)
),
'content_type': github_settings.HOOK_CONTENT_TYPE,
'secret': secret,
},
events=github_settings.HOOK_EVENTS,
)
except ApiError:
pass
if hook:
database['addongithubnodesettings'].find_and_modify(
{'_id': document['_id']},
{
'$set': {
'hook_id': hook.id,
'hook_secret': secret
}
}
)
示例3: test_POST_register_make_public_immediately_makes_children_public
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def test_POST_register_make_public_immediately_makes_children_public(self, mock_enqueue):
component = NodeFactory(
creator=self.user,
parent=self.project,
title='Component'
)
subproject = ProjectFactory(
creator=self.user,
parent=self.project,
title='Subproject'
)
subproject_component = NodeFactory(
creator=self.user,
parent=subproject,
title='Subcomponent'
)
res = self.app.post(
self.project.api_url_for('node_register_template_page_post', template=u'Open-Ended_Registration'),
self.valid_make_public_payload,
content_type='application/json',
auth=self.user.auth
)
self.project.reload()
# Last node directly registered from self.project
registration = Node.load(self.project.node__registrations[-1])
assert_true(registration.is_public)
for node in registration.get_descendants_recursive():
assert_true(node.is_registration)
assert_true(node.is_public)
示例4: test_bulk_creates_children_and_sanitizes_html_logged_in_owner
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def test_bulk_creates_children_and_sanitizes_html_logged_in_owner(self):
title = "<em>Cool</em> <strong>Project</strong>"
description = 'An <script>alert("even cooler")</script> child'
res = self.app.post_json_api(
self.url,
{
"data": [
{
"type": "nodes",
"attributes": {
"title": title,
"description": description,
"category": "project",
"public": True,
},
}
]
},
auth=self.user.auth,
bulk=True,
)
child_id = res.json["data"][0]["id"]
assert_equal(res.status_code, 201)
url = "/{}nodes/{}/".format(API_BASE, child_id)
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.json["data"]["attributes"]["title"], strip_html(title))
assert_equal(res.json["data"]["attributes"]["description"], strip_html(description))
assert_equal(res.json["data"]["attributes"]["category"], "project")
self.project.reload()
child_id = res.json["data"]["id"]
assert_equal(child_id, self.project.nodes[0]._id)
assert_equal(Node.load(child_id).logs[0].action, NodeLog.PROJECT_CREATED)
示例5: has_object_permission
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def has_object_permission(self, request, view, obj):
if not isinstance(obj, Node):
obj = Node.load(request.parser_context['kwargs'][view.node_lookup_url_kwarg])
assert isinstance(obj, Node), 'obj must be a Node'
if obj.is_registration:
return request.method in permissions.SAFE_METHODS
return True
示例6: project_generate_private_link_post
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def project_generate_private_link_post(auth, node, **kwargs):
""" creata a new private link object and add it to the node and its selected children"""
node_ids = request.json.get('node_ids', [])
name = request.json.get('name', '')
anonymous = request.json.get('anonymous', False)
if node._id not in node_ids:
node_ids.insert(0, node._id)
nodes = [Node.load(node_id) for node_id in node_ids]
has_public_node = any(node.is_public for node in nodes)
new_link = new_private_link(
name=name, user=auth.user, nodes=nodes, anonymous=anonymous
)
if anonymous and has_public_node:
status.push_status_message(
'Anonymized view-only links <b>DO NOT</b> '
'anonymize contributors of public project or component.'
)
return new_link
示例7: project_generate_private_link_post
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def project_generate_private_link_post(auth, node, **kwargs):
""" creata a new private link object and add it to the node and its selected children"""
node_ids = request.json.get('node_ids', [])
name = request.json.get('name', '')
anonymous = request.json.get('anonymous', False)
if node._id not in node_ids:
node_ids.insert(0, node._id)
nodes = [Node.load(node_id) for node_id in node_ids]
has_public_node = any(node.is_public for node in nodes)
try:
new_link = new_private_link(
name=name, user=auth.user, nodes=nodes, anonymous=anonymous
)
except ValidationValueError as e:
raise HTTPError(
http.BAD_REQUEST,
data=dict(message_long=e.message)
)
if anonymous and has_public_node:
status.push_status_message(
'Anonymized view-only links <b>DO NOT</b> '
'anonymize contributors of public projects or components.',
trust=True
)
return new_link
示例8: get_object
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def get_object(self):
link_id = self.kwargs['link_id']
view_only_link = PrivateLink.load(link_id)
return {
'data': [Node.load(node) for node in view_only_link.nodes],
'self': view_only_link
}
示例9: main
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def main():
nodes = Node.objects.all()
total = len(nodes)
count = 0
page_size = 1000
while count < total:
for node in nodes[count:count+page_size]:
modm_node = MODMNode.load(node._guid.guid)
verify_contributors(node, modm_node)
verify_tags(node, modm_node)
count += 1
if count % (total * .001) == 0:
floatal = float(total)
flount = float(count)
print 'Verified nodes {}%'.format((
(floatal - flount) / floatal - 1.0) * -100.0)
# clear out
modm_node = None
node = None
floatal = None
flount = None
if count % page_size == 0:
garbage = gc.collect()
print '{}:{} Collected {} whole garbages...'.format(count, total,
garbage)
print '\a'
print '\a'
print '\a'
print '\a'
print '\a'
示例10: test_bulk_creates_children_and_sanitizes_html_logged_in_owner
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def test_bulk_creates_children_and_sanitizes_html_logged_in_owner(self):
title = '<em>Cool</em> <strong>Project</strong>'
description = 'An <script>alert("even cooler")</script> child'
res = self.app.post_json_api(self.url, {
'data': [{
'type': 'nodes',
'attributes': {
'title': title,
'description': description,
'category': 'project',
'public': True
}
}]
}, auth=self.user.auth, bulk=True)
child_id = res.json['data'][0]['id']
assert_equal(res.status_code, 201)
url = '/{}nodes/{}/'.format(API_BASE, child_id)
res = self.app.get(url, auth=self.user.auth)
assert_equal(res.json['data']['attributes']['title'], strip_html(title))
assert_equal(res.json['data']['attributes']['description'], strip_html(description))
assert_equal(res.json['data']['attributes']['category'], 'project')
self.project.reload()
child_id = res.json['data']['id']
assert_equal(child_id, self.project.nodes[0]._id)
assert_equal(Node.load(child_id).logs[0].action, NodeLog.PROJECT_CREATED)
示例11: project_contributors_post
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def project_contributors_post(auth, node, **kwargs):
""" Add contributors to a node. """
user_dicts = request.json.get('users')
node_ids = request.json.get('node_ids')
if user_dicts is None or node_ids is None:
raise HTTPError(http.BAD_REQUEST)
# Prepare input data for `Node::add_contributors`
contribs = deserialize_contributors(node, user_dicts, auth=auth)
node.add_contributors(contributors=contribs, auth=auth)
node.save()
# Disconnect listener to avoid multiple invite emails
unreg_contributor_added.disconnect(finalize_invitation)
for child_id in node_ids:
child = Node.load(child_id)
# Only email unreg users once
child_contribs = deserialize_contributors(
child, user_dicts, auth=auth
)
child.add_contributors(contributors=child_contribs, auth=auth)
child.save()
# Reconnect listener
unreg_contributor_added.connect(finalize_invitation)
return {'status': 'success'}, 201
示例12: test_make_new_node_settings
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def test_make_new_node_settings(self):
node_settings_document = self.node_settings_documents[0]
node = Node.load(node_settings_document['owner'])
user_settings_document = database['addons3usersettings'].find_one({
'_id': node_settings_document['user_settings']
})
external_account, user, new = migration.migrate_to_external_account(
user_settings_document
)
user_settings = migration.make_new_user_settings(user)
node_settings = migration.make_new_node_settings(
node,
node_settings_document,
external_account,
user_settings
)
assert(
'addons3nodesettings' not in node._backrefs['addons']
)
assert_equal(
len(node._backrefs['addons']['s3nodesettings']['owner']),
1
)
assert_equal(
node._backrefs['addons']['s3nodesettings']['owner'][0],
node_settings._id
)
示例13: test_POST_register_embargo_does_not_make_project_or_children_public
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def test_POST_register_embargo_does_not_make_project_or_children_public(self, mock_enqueue):
public_project = ProjectFactory(creator=self.user, is_public=True)
component = NodeFactory(creator=self.user, parent=public_project, title="Component", is_public=True)
subproject = ProjectFactory(creator=self.user, parent=public_project, title="Subproject", is_public=True)
subproject_component = NodeFactory(creator=self.user, parent=subproject, title="Subcomponent", is_public=True)
res = self.app.post(
public_project.api_url_for("node_register_template_page_post", template=u"Open-Ended_Registration"),
self.valid_embargo_payload,
content_type="application/json",
auth=self.user.auth,
)
public_project.reload()
assert_equal(res.status_code, 201)
# Last node directly registered from self.project
registration = Node.load(public_project.node__registrations[-1])
assert_true(registration.is_registration)
assert_false(registration.is_public)
assert_true(registration.is_pending_embargo_for_existing_registration)
assert_is_not_none(registration.embargo)
for node in registration.get_descendants_recursive():
assert_true(node.is_registration)
assert_false(node.is_public)
示例14: create
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def create(self, validated_data):
request = self.context['request']
user = request.user
if 'template_from' in validated_data:
template_from = validated_data.pop('template_from')
template_node = Node.load(key=template_from)
if template_node is None:
raise exceptions.NotFound
if not template_node.has_permission(user, 'read', check_parent=False):
raise exceptions.PermissionDenied
validated_data.pop('creator')
changed_data = {template_from: validated_data}
node = template_node.use_as_template(auth=get_user_auth(request), changes=changed_data)
else:
node = Node(**validated_data)
try:
node.save()
except ValidationValueError as e:
raise InvalidModelValueError(detail=e.message)
if is_truthy(request.GET.get('inherit_contributors')) and validated_data['parent'].has_permission(user, 'write'):
auth = get_user_auth(request)
parent = validated_data['parent']
contributors = []
for contributor in parent.contributors:
if contributor is not user:
contributors.append({
'user': contributor,
'permissions': parent.get_permissions(contributor),
'visible': parent.get_visible(contributor)
})
node.add_contributors(contributors, auth=auth, log=True, save=True)
return node
示例15: get_configured_projects
# 需要导入模块: from website.models import Node [as 别名]
# 或者: from website.models.Node import load [as 别名]
def get_configured_projects(user):
"""Filter all user subscriptions for ones that are on parent projects
and return the project ids.
:param user: modular odm User object
:return: list of project ids for projects with no parent
"""
configured_project_ids = set()
user_subscriptions = get_all_user_subscriptions(user)
for subscription in user_subscriptions:
if subscription is None:
continue
# If the user has opted out of emails skip
node = subscription.owner
if not isinstance(node, Node) or (user in subscription.none and not node.parent_id):
continue
while node.parent_id and not node.is_deleted:
node = Node.load(node.parent_id)
if not node.is_deleted:
configured_project_ids.add(node._id)
return list(configured_project_ids)