本文整理汇总了Python中models.Entry.check_slug方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.check_slug方法的具体用法?Python Entry.check_slug怎么用?Python Entry.check_slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.check_slug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_or_edit
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import check_slug [as 别名]
def _create_or_edit(self, entry_key, status):
title, slug, markdown, author, kind_name, reference = self.get_argument('title'), \
self.get_argument('slug', ''), \
self.get_argument('content', strip=False), \
self.get_argument('author', None), \
self.get_argument('kind_name', None), \
self.get_argument('reference', None)
# Check title and markdown is empty.
if not (title and markdown):
raise SaveException('标题或者内容为空!')
if not slug:
slug = title
slug = Entry.check_slug(slug, entry_key)
if slug==None:
raise SlugException('该 Slug 已经存在!')
now = get_now()
if entry_key:
entry = db.get(entry_key)
if entry.entry_kind.name != 'blog':
if not author:
raise Exception('作者未知!')
entry.author = author
entry.title = title
entry.slug = slug
entry.markdown = markdown
entry.html = Entry.convert(markdown)
entry.abstract = self._process_abstract(markdown)
if entry.status == 'draft':
entry.published = now
else:
entry.updated = now
entry.status = status
else:
if kind_name not in KINDS:
raise Exception('非法类型文章!')
if kind_name == 'blog':
author = self.current_user.nickname()
if not author:
raise Exception('作者未知!')
entry = Entry(
entry_kind = KINDS.get(kind_name),
author = author or self.current_user.nickname(),
reference = reference,
title = title,
slug = slug,
markdown = markdown,
html = Entry.convert(markdown),
abstract = self._process_abstract(markdown),
status = status,
published = now
)
entry.put()
return entry
示例2: get
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import check_slug [as 别名]
def get(self, slug):
entry_key = self.get_argument('entry_key', None)
self.write({
'name': 'slug',
'validate': Entry.check_slug(slug, entry_key)!=None,
})