本文整理汇总了Python中models.Comment.find_all方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.find_all方法的具体用法?Python Comment.find_all怎么用?Python Comment.find_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.find_all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: weibo_tag
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import find_all [as 别名]
def weibo_tag(weibo):
comment_list = Comment.find_all(weibo_id=weibo.id)
comments = '<br>'.join([c.content for c in comment_list])
# format 函数的字典用法
# 注意 u.id 是 current_user
# user.username 是博主
w = {
'id': weibo.id,
'user_id': u.id,
'content': weibo.content,
'username': user.username,
'time': weibo.created_time,
'comments': comments,
}
# 手动处理 weibos 这个 list
# 把每个 weibo 以 <p> 的形式展现在页面
return """
<p>{content} from {username}@{time}
<a href="/weibo/delete?id={id}">删除</a>
<a href="/weibo/edit?id={id}">修改</a></p>
<button class="weibo-show-comment" data-id="{id}">评论</button>
<div>
{comments}
</div>
<div id="id-div-comment-{id}" class="weibo-comment-form weibo-hide">
<form action="/weibo/comment/add" method="post">
<input name="user_id" value="{user_id}" type="hidden">
<input name="weibo_id" value="{id}" type="hidden">
<textarea name="content"></textarea>
<button type="submit">添加评论</button>
</form>
</div>
</p>
""".format(**w)
示例2: api_comments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import find_all [as 别名]
def api_comments(*, page='1'):
page_index = get_page_index(page)
num = yield from Comment.find_num('count(id)')
p = Page(num, page_index)
if num == 0:
return dict(page=p, comments=())
comments = yield from Comment.find_all(orderBy='created_at desc', limit=(p.offset, p.limit))
return dict(page=p, comments=comments)
示例3: api_delete_blog
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import find_all [as 别名]
def api_delete_blog(request, *, id):
check_admin(request)
blog = yield from Blog.find(id)
yield from blog.remove()
comments = yield from Comment.find_all('blog_id=?', [id])
for c in comments:
yield from c.remove()
return dict(id=id)
示例4: get_blog
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import find_all [as 别名]
def get_blog(id):
blog = yield from Blog.find(id)
comments = yield from Comment.find_all('blog_id=?', [id], orderBy='created_at desc')
for c in comments:
c.html_content = text2html(c.content)
blog.html_content = markdown2.markdown(blog.content)
return {
'__template__': 'blog.html',
'blog': blog,
'comments': comments
}
示例5: blog_id
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import find_all [as 别名]
def blog_id(id):
if request.method == 'POST':
comment_content = request.form['comment_content']
comment_name = request.form['comment_name']
comment = Comment(id=next_id(), blog_id=id, user_id='guest', user_name=comment_name,
user_image='',
content=comment_content, created_at=time.time())
comment.save()
image = common.create_avatar_by_name(comment_name)
user = User(id=next_id(), email='', passwd='', admin=0, name=comment_name,
image=image,
created_at=time.time())
mylog.info(image)
# TODO 先使用name来进行判定是否唯一,后期希望能够使用email来判断是否唯一
_user = User.find_all('name= ?', [comment_name])
if len(_user) == 0:
user.save()
flash('comment and new user had been saved successfully!')
blog = Blog.find(id)
md_text = highlight.parse2markdown(blog.content)
blog.html_content = md_text
comments = Comment.find_all('blog_id= ?', [id])
return render_template('blogdetail.html', blog=blog, comments=comments)