本文整理汇总了Python中models.Page.one方法的典型用法代码示例。如果您正苦于以下问题:Python Page.one方法的具体用法?Python Page.one怎么用?Python Page.one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.one方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import one [as 别名]
def post(self, slug=None):
f = page_form()
data = self.get_arguments()
is_edit = data.has_key('ori_slug')
_ = self._
try:
attachments = self.get_argument('attachments', None)
if attachments:
data['attachments'] = parse_attachments(data['attachments'], is_edit)
if f.validates(tornado.web._O(data)):
page = Page.one({'type': 'Page', 'slug': data['ori_slug']}) \
if is_edit else Page()
page.save(data, user=self.current_user)
if attachments:
page['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
page.update_html()
page.save()
self.set_flash(_("Page has been saved."))
self.redirect(page.get_url())
return
page = Page()
raise Exception(_("Invalid form data."))
except Exception, e:
if attachments:
page['attachments'] = data['attachments']
f.note = f.note if f.note else e
self.render("page-edit", f=f, page=page, user=self.current_user)
示例2: get
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import one [as 别名]
def get(self, slug=None):
f = page_form()
if slug:
try:
page = Page.one({'type': 'Page', 'slug': slug})
page.check_edit_permission(self.get_current_user())
page.formify()
f.fill(page)
except EditDisallowedError:
self.set_flash(self._("You are not allowed to edit that page."))
self.redirect(page.get_url())
return
except:
raise tornado.web.HTTPError(404)
else:
page = Page()
self.render("page-edit", f=f, page=page, user=self.current_user)