本文整理汇总了Python中models.Post.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get_by_key_name方法的具体用法?Python Post.get_by_key_name怎么用?Python Post.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.get_by_key_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tnx
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_by_key_name [as 别名]
def tnx():
entity = Post.get_by_key_name(key_name)
if entity is None:
entity = Post(key_name=key_name, **kwds)
entity.put()
return (True, entity)
return (False, entity)
示例2: search
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_by_key_name [as 别名]
def search(user, query, type='and'):
if type == 'phrase':
ids = _phrase_search(user, query)
else:
ids = _and_search(user, query)
#logging.info(ids)
posts = Post.get_by_key_name(ids, parent=user)
#logging.info(posts[0].message)
return sorted(posts, key=operator.attrgetter('created_time'), reverse=True)
示例3: show
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_by_key_name [as 别名]
def show(request, key):
prevent_cache = False
post = Post.get_by_key_name('Published:%s' % key)
if not post and users.is_current_user_admin():
# admin might also try to retrieve the post by it's key!
post = Post.get_by_key_name(key)
prevent_cache = True
if post:
ns = NutSettings()
template = ns.articles_layout
if template:
template = 'nut:layout/%s' % template
else:
template = 'app:articles/show.html'
resp = render_template(template, post=post)
resp.prevent_cache = prevent_cache
else:
resp = render_template('app/404.html')
resp.prevent_cache = True
return resp
示例4: edit
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_by_key_name [as 别名]
def edit(request, key):
post = Post.get_by_key_name(key)
form = ArticleForm(request.form, obj=PostProxy(post), prefix='edit')
status = False
if request.method == 'POST' and form.validate():
key_name, kwds = prepare(form)
# kwds['html'] = render_jinja('cache_body.html', body=kwds['body'])
if post.key().name() == key_name:
post = update_entity(key_name, **kwds)
status = 'Updated'
else:
kwds['author'] = users.get_current_user()
created, entity = create_entity(key_name, **kwds)
if not created:
return Response('sorry, post with that pub_date and title'\
+ 'exists already')
post.invalidate_cache()
post.delete()
post = entity
status = 'Updated'
post.invalidate_cache()
if form.save.data:
return redirect(url_for('nut:articles/list'), 301)
return render_template('app:articles/form.html', form=form, post=post, status=status)
示例5: delete
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_by_key_name [as 别名]
def delete(request, key):
post = Post.get_by_key_name(key)
if request.method == 'POST':
post.delete()
return redirect(url_for('nut:articles/list'), 301)
return render_template('app:articles/post_confirm_delete.html', post=post)