本文整理汇总了Python中models.Comment.create_time方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create_time方法的具体用法?Python Comment.create_time怎么用?Python Comment.create_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.create_time方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create_time [as 别名]
def post(self, title):
post = yield Post.asyncQuery(title=title).first()
if not post:
raise tornado.web.HTTPError(404)
if self.form.validate():
comment = Comment()
comment.create_time = datetime.datetime.utcnow()
comment.author_name = self.form.author_name.data
comment.author_email = self.form.author_email.data
comment.author_url = self.form.author_url.data
# Direct use user post data is unsafe,
# so we convert `org_markdown_text` in the back-end
comment.content = markdown2.markdown(self.form.content.data)
post.comments.append(comment)
yield post.save()
self.flash("评论提交成功~")
return self.redirect("{path}{id}".format(
path=self.request.path, id="#comment"))
self.render("post.html", post=post, form=self.form)
示例2: import_blog
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create_time [as 别名]
def import_blog():
f = request.files["file"]
try:
data = f.stream.read().decode("utf-8")
data = json.loads(data)
links = data.pop("links", [])
medias = data.pop("medias", [])
posts = data.pop("posts", [])
for link in links:
new_link = Link.get_by_href(link["href"])
if new_link:
continue
else:
new_link = Link()
for item in link:
new_link.__dict__[item] = link[item]
new_link.link_id = None
new_link.create_time = \
datetime.fromtimestamp(new_link.create_time)
new_link.save()
for media in medias:
new_media = Media.get_by_fileid(media["fileid"])
if new_media:
continue
else:
new_media = Media()
for item in media:
new_media.__dict__[item] = media[item]
# Notice, media id should not be set to None
new_media.media_id = None
new_media.create_time = \
datetime.fromtimestamp(new_media.create_time)
new_media.save()
for post in posts:
# If posts exist, continue
new_post = Post.get_by_url(post["url"], public_only=False)
if new_post:
continue
else:
new_post = Post()
for item in post:
new_post.__dict__[item] = post[item]
new_post.post_id = None
new_post.create_time = \
datetime.fromtimestamp(new_post.create_time)
new_post.update_time = \
datetime.fromtimestamp(new_post.update_time)
new_post.raw_content = re.sub('<[^<]+?>', "", new_post.content)
newtags = new_post.tags
new_post.tags = ""
new_post.update_tags(newtags)
new_post.save()
# Restore all posts
comments = post["commentlist"]
for comment in comments:
new_comment = Comment()
for item in comment:
new_comment.__dict__[item] = comment[item]
new_comment.post_id = new_post.post_id
new_comment.comment_id = None
new_comment.create_time = \
datetime.fromtimestamp(new_comment.create_time)
new_comment.save()
except Exception as e:
return str(e)
return "Done"