本文整理汇总了Python中models.Entry.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.get_by_key_name方法的具体用法?Python Entry.get_by_key_name怎么用?Python Entry.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.get_by_key_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autosave
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_key_name [as 别名]
def autosave(handler, route, params):
title = params.get("title", "")
content = params.get("content", "")
key = params.get("key", None)
user = handler.session.get("account", False)
if not title or not content:
return {"saved": False}
if not user:
return {"account": False, "saved": False}
if key:
draft = Entry.get_by_key_name(key)
if str(draft._author) != user:
raise Exception("You are not this article's author")
else:
key = str(time.time()).replace(".", "")
draft = Entry(key_name=key, author=db.Key(user))
draft.title = title
draft.content = content
draft.put()
return {"saved": key, "time": draft.isodate}
示例2: delete_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_key_name [as 别名]
def delete_entry(filename):
basename, extension = splitext(filename)
entry = Entry.get_by_key_name(basename)
if entry:
entry.delete()
示例3: article
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_key_name [as 别名]
def article(handler, route, params):
if route.get("key", False):
draft = Entry.get_by_key_name(route.get("key"))
return {"article": draft}
return {"__redirect_to": "/writer/"}
示例4: draft
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_key_name [as 别名]
def draft(handler, route, params):
if route.get("key", False):
draft = Entry.get_by_key_name(route.get("key"))
if draft and str(draft._author) == handler.session.get("account", False):
return {"draft": draft}
return {"draft": {"title": "untitled", "content": "", "saved": "never"}}