本文整理汇总了Python中website.project.new_node函数的典型用法代码示例。如果您正苦于以下问题:Python new_node函数的具体用法?Python new_node怎么用?Python new_node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了new_node函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: project_new_post
def project_new_post(auth, **kwargs):
user = auth.user
title = strip_html(request.json.get('title'))
template = request.json.get('template')
description = strip_html(request.json.get('description'))
title = title.strip()
if not title or len(title) > 200:
raise HTTPError(http.BAD_REQUEST)
if template:
original_node = Node.load(template)
changes = {
'title': title
}
if description:
changes['description'] = description
project = original_node.use_as_template(
auth=auth,
changes={
template: changes
})
else:
project = new_node('project', title, user, description)
return {
'projectUrl': project.url
}, http.CREATED
示例2: project_new_node
def project_new_node(auth, node, **kwargs):
form = NewNodeForm(request.form)
user = auth.user
if form.validate():
try:
new_component = new_node(
title=strip_html(form.title.data),
user=user,
category=form.category.data,
parent=node,
)
except ValidationValueError as e:
raise HTTPError(
http.BAD_REQUEST,
data=dict(message_long=e.message)
)
message = (
'Your component was created successfully. You can keep working on the component page below, '
'or return to the <u><a href="{url}">project page</a></u>.'
).format(url=node.url)
status.push_status_message(message, kind='info', trust=True)
return {
'status': 'success',
}, 201, None, new_component.url
else:
# TODO: This function doesn't seem to exist anymore?
status.push_errors_to_status(form.errors)
raise HTTPError(http.BAD_REQUEST, redirect_url=node.url)
示例3: project_new_post
def project_new_post(auth, **kwargs):
user = auth.user
data = request.get_json()
title = strip_html(data.get("title"))
title = title.strip()
category = data.get("category", "project")
template = data.get("template")
description = strip_html(data.get("description"))
new_project = {}
if template:
original_node = Node.load(template)
changes = {"title": title, "category": category, "template_node": original_node}
if description:
changes["description"] = description
project = original_node.use_as_template(auth=auth, changes={template: changes})
else:
try:
project = new_node(category, title, user, description)
except ValidationValueError as e:
raise HTTPError(http.BAD_REQUEST, data=dict(message_long=e.message))
new_project = _view_project(project, auth)
return {"projectUrl": project.url, "newNode": new_project["node"] if new_project else None}, http.CREATED
示例4: project_new_node
def project_new_node(auth, node, **kwargs):
form = NewNodeForm(request.form)
user = auth.user
if form.validate():
try:
new_component = new_node(
title=strip_html(form.title.data),
user=user,
category=form.category.data,
parent=node,
)
except ValidationError as e:
raise HTTPError(
http.BAD_REQUEST,
data=dict(message_long=e.message)
)
redirect_url = node.url
message = (
'Your component was created successfully. You can keep working on the project page below, '
'or go to the new <u><a href={component_url}>component</a></u>.'
).format(component_url=new_component.url)
if form.inherit_contributors.data and node.has_permission(user, WRITE):
for contributor in node.contributors:
perm = CREATOR_PERMISSIONS if contributor._id == user._id else node.get_permissions(contributor)
if contributor._id == user._id and not contributor.is_registered:
new_component.add_unregistered_contributor(
fullname=contributor.fullname, email=contributor.email,
permissions=perm, auth=auth, existing_user=contributor
)
else:
new_component.add_contributor(contributor, permissions=perm, auth=auth)
new_component.save()
redirect_url = new_component.url + 'contributors/'
message = (
'Your component was created successfully. You can edit the contributor permissions below, '
'work on your <u><a href={component_url}>component</a></u> or return to the <u> '
'<a href="{project_url}">project page</a></u>.'
).format(component_url=new_component.url, project_url=node.url)
status.push_status_message(message, kind='info', trust=True)
return {
'status': 'success',
}, 201, None, redirect_url
else:
# TODO: This function doesn't seem to exist anymore?
status.push_errors_to_status(form.errors)
raise HTTPError(http.BAD_REQUEST, redirect_url=node.url)
示例5: get_or_create_node
def get_or_create_node(title, user):
"""Get or create node by title and creating user.
:param str title: Node title
:param User user: User creating node
:return: Tuple of (node, created)
"""
try:
node = Node.find_one(
Q('title', 'iexact', title)
& Q('contributors', 'eq', user._id)
)
return node, False
except ModularOdmException:
node = new_node('project', title, user)
return node, True
示例6: project_new_post
def project_new_post(auth, **kwargs):
user = auth.user
data = request.get_json()
title = strip_html(data.get('title'))
title = title.strip()
category = data.get('category', 'project')
template = data.get('template')
description = strip_html(data.get('description'))
new_project = {}
if template:
original_node = Node.load(template)
changes = {
'title': title,
'category': category,
'template_node': original_node,
}
if description:
changes['description'] = description
project = original_node.use_as_template(
auth=auth,
changes={
template: changes,
}
)
else:
try:
project = new_node(category, title, user, description)
except ValidationError as e:
raise HTTPError(
http.BAD_REQUEST,
data=dict(message_long=e.message)
)
new_project = _view_project(project, auth)
return {
'projectUrl': project.url,
'newNode': new_project['node'] if new_project else None
}, http.CREATED
示例7: project_new_node
def project_new_node(auth, node, **kwargs):
form = NewNodeForm(request.form)
user = auth.user
if form.validate():
try:
new_component = new_node(
title=strip_html(form.title.data),
user=user,
category=form.category.data,
parent=node,
)
except ValidationValueError as e:
raise HTTPError(
http.BAD_REQUEST,
data=dict(message_long=e.message)
)
redirect_url = new_component.url
message = (
'Your component was created successfully. You can keep working on the component page below, '
'or return to the <u><a href="{url}">project page</a></u>.'
).format(url=node.url)
if form.inherit_contributors.data and node.has_permission(user, ADMIN):
for contributor in node.contributors:
new_component.add_contributor(contributor, permissions=node.get_permissions(contributor), auth=auth)
new_component.save()
redirect_url = redirect_url + 'contributors/'
message = (
'Your component was created successfully. You can edit the contributor permissions below, '
'work on your <u><a href=' + new_component.url +
'>component</a></u> or return to the <u><a href="{url}">project page</a></u>.'
).format(url=node.url)
status.push_status_message(message, kind='info', trust=True)
return {
'status': 'success',
}, 201, None, redirect_url
else:
# TODO: This function doesn't seem to exist anymore?
status.push_errors_to_status(form.errors)
raise HTTPError(http.BAD_REQUEST, redirect_url=node.url)
示例8: project_new_node
def project_new_node(auth, node, **kwargs):
form = NewNodeForm(request.form)
user = auth.user
if form.validate():
node = new_node(
title=strip_html(form.title.data),
user=user,
category=form.category.data,
parent=node,
)
message = (
'Your component was created successfully. You can keep working on the component page below, '
'or return to the <u><a href="{url}">Project Page</a></u>.'
).format(url=node.url)
status.push_status_message(message, 'info')
return {
'status': 'success',
}, 201, None, node.url
else:
status.push_errors_to_status(form.errors)
raise HTTPError(http.BAD_REQUEST, redirect_url=node.url)
示例9: project_new_post
def project_new_post(auth, **kwargs):
user = auth.user
data = request.get_json()
title = strip_html(data.get('title'))
title = title.strip()
category = data.get('category', 'project')
template = data.get('template')
description = strip_html(data.get('description'))
if not title or len(title) > 200:
raise HTTPError(http.BAD_REQUEST)
if template:
original_node = Node.load(template)
changes = {
'title': title,
'category': category,
'template_node': original_node,
}
if description:
changes['description'] = description
project = original_node.use_as_template(
auth=auth,
changes={
template: changes,
}
)
else:
project = new_node(category, title, user, description)
return {
'projectUrl': project.url
}, http.CREATED
示例10: add_poster_by_email
def add_poster_by_email(conf, recipient, address, fullname, subject,
message, attachments, tags=None, system_tags=None,
is_spam=False):
# Fail if no attachments
if not attachments:
send_mail(
address,
CONFERENCE_FAILED,
fullname=fullname,
)
return
# Use address as name if name missing
fullname = fullname or address.split('@')[0]
created = []
user, user_created = get_or_create_user(fullname, address, is_spam)
if user_created:
created.append(user)
set_password_url = web_url_for(
'reset_password',
verification_key=user.verification_key,
)
else:
set_password_url = None
auth = Auth(user=user)
# Find or create node
node = Node.find(Q('title', 'iexact', subject))
node = node[0] if node.count() else None
if node is None or not node.is_contributor(user):
node = new_node('project', subject, user)
created.append(node)
# Add admin to project
if conf.admins:
for admin in conf.admins:
node.add_contributor(
contributor=admin,
visible=False,
log=False,
save=True
)
# Make public if confident that this is not spam and projects made public
if is_spam:
logger.warn(
'Possible spam detected in email modification of '
'user {0} / node {1}'.format(
user._id, node._id,
)
)
elif conf.public_projects:
node.set_privacy('public', auth=auth)
# Add body
node.update_node_wiki('home', sanitize(message), auth)
# Add tags
presentation_type = 'talk' if 'talk' in recipient else 'poster'
tags = tags or []
tags.append(presentation_type)
for tag in tags:
node.add_tag(tag, auth=auth)
# Add system tags
system_tags = system_tags or []
system_tags.append(presentation_type)
system_tags.append('emailed')
if is_spam:
system_tags.append('spam')
for tag in system_tags:
if tag not in node.system_tags:
node.system_tags.append(tag)
# Save changes
node.save()
from website.addons.osfstorage import utils as storage_utils
# Add files
for attachment in attachments:
name, content, content_type, size = prepare_file(attachment)
upload_url = storage_utils.get_upload_url(node, user, size, content_type, name)
requests.put(
upload_url,
data=content,
headers={'Content-Type': content_type},
)
download_url = node.web_url_for(
'osf_storage_view_file',
path=attachments[0].filename,
action='download',
)
#.........这里部分代码省略.........