本文整理汇总了Python中models.Category.asyncQuery方法的典型用法代码示例。如果您正苦于以下问题:Python Category.asyncQuery方法的具体用法?Python Category.asyncQuery怎么用?Python Category.asyncQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.asyncQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import asyncQuery [as 别名]
def get(self, category, page):
if not page:
page = 1
if not category:
category = "All"
if category.upper() == "ALL":
posts = yield Post.asyncQuery().order_by("-create_time").paginate(
page=int(page), per_page=self.settings['per_page'])
else:
c = yield Category.asyncQuery(name=category).first()
if not c:
raise tornado.web.HTTPError(404)
posts = yield Post.asyncQuery(
category=c).order_by("-create_time").paginate(
page=int(page), per_page=self.settings['per_page'])
categorys = yield Category.asyncQuery()
self.render("blog.html",
posts=posts,
categorys=categorys,
current_category=category)
示例2: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import asyncQuery [as 别名]
def post(self, title):
if self.form.validate():
post = None
if self.form.post_id.data:
post = yield Post.asyncQuery(id=self.form.post_id.data).first()
if post:
post.modified_time = datetime.datetime.utcnow()
else:
post = Post()
post.create_time = \
self.BeiJing2UTCTime(self.form.create_time.data)
title = self.form.title.data.replace(' ', '-')
content = self.form.content.data
markdown_text = self.form.markdown.data
tags = self.separate_tags(self.form.tags.data)
category_str = self.form.category.data.capitalize()
category = yield Category.asyncQuery(
name=category_str).first()
if not category:
category = Category()
category.name = category_str
yield category.save()
post.title = title
post.content = content
post.markdown = markdown_text
post.category = category
post.tags = tags
post.author = self.current_user
yield post.save()
self.flash("compose finsh!")
return self.redirect('/blog')
self.render("compose.html", form=self.form)