本文整理汇总了Python中models.Node.add方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add方法的具体用法?Python Node.add怎么用?Python Node.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add [as 别名]
def add(request, key):
""" add a new page
to the set"""
to = key # lame but it does the trick for now
blocks = []
form = PageForm(request.form)
add = BlockAddForm(request.form, prefix='_add')
form.layout.choices = Layout.get_key_to_path()
if request.method == 'POST':
# some logic to find __block elements.
for key in request.form:
if key.startswith('__block:'):
name = key.split('__',2)[1][6:]
blocks.append((name, BlockForm(request.form, prefix='__block:%s__' % name)))
if add.validate() and add.add.data is True:
blocks.append((add.name.data, BlockForm(prefix='__block:%s__' % add.name.data)))
add = BlockAddForm(prefix='_add')
elif form.validate() and all([block.validate() for _, block in blocks]):
name = form.name.data
slug = form.slug.data
breadcrumb = form.breadcrumb.data
state = form.state.data
active = form.active.data
if len(slug) < 1:
slug = slugify(name)
author = users.get_current_user()
updated = datetime.now()
description = form.description.data
keywords = form.keywords.data
body = form.body.data
content_type = form.content_type.data
if form.layout.data == 'Layout:None':
layout = None
else:
layout = Layout.get(form.layout.data.split(':',1)[1])
page = Node.add(to=to, name=name, slug=slug, breadcrumb=breadcrumb,
updated=updated, author=author, body=body,
description=description, keywords=keywords, layout=layout,
content_type=content_type,
state=state, active=active, type=PAGE)
done = []
try:
for name, block in blocks:
b = Block(node=page, name=name, body=block.body.data)
b.put()
done.append(b)
except:
db.delete(done)
Node.drop(page.get_key())
if form.save.data is True:
return redirect(url_for('nut:pages/list_pages'), 301)
if form.cont.data is True:
return redirect(url_for('nut:pages/edit', key=page.get_key()), 301)
return render_template('app:pages/form.html', form=form, add=add, blocks=blocks)
示例2: add_folder
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import add [as 别名]
def add_folder(request):
form = FolderForm(request.form)
if request.method == 'POST' and form.validate():
name = form.name.data
slug = form.slug.data
breadcrumb = form.breadcrumb.data
state = form.state.data
active = form.active.data
if len(slug) < 1:
slug = slugify(name)
author = users.get_current_user()
updated = datetime.now()
page = Node.add(name=name, slug=slug, breadcrumb=breadcrumb,
updated=updated, author=author,
state=state, active=active, type=FOLDER)
if form.save.data is True:
return redirect(url_for('nut:pages/list_pages'), 301)
if form.cont.data is True:
return redirect(url_for('nut:pages/edit', key=page.get_key()), 301)
return render_template('app:pages/form.html', form=form)