本文整理汇总了Python中assembl.models.Idea.idea_counts方法的典型用法代码示例。如果您正苦于以下问题:Python Idea.idea_counts方法的具体用法?Python Idea.idea_counts怎么用?Python Idea.idea_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assembl.models.Idea
的用法示例。
在下文中一共展示了Idea.idea_counts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mark_post_read
# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import idea_counts [as 别名]
def mark_post_read(request):
discussion_id = int(request.matchdict["discussion_id"])
discussion = Discussion.get_instance(discussion_id)
post_id = request.matchdict["id"]
post = Post.get_instance(post_id)
if not post:
raise HTTPNotFound("Post with id '%s' not found." % post_id)
post_id = post.id
user_id = authenticated_userid(request)
if not user_id:
raise HTTPUnauthorized()
read_data = json.loads(request.body)
db = Discussion.db()
change = False
with transaction.manager:
if read_data.get("read", None) is False:
view = db.query(ViewPost).filter(ViewPost.post_id == post_id).filter(Action.actor_id == user_id).first()
if view:
change = True
db.delete(view)
else:
count = db.query(ViewPost).filter(ViewPost.post_id == post_id).filter(Action.actor_id == user_id).count()
if not count:
change = True
db.add(ViewPost(post=post, actor_id=user_id))
new_counts = []
if change:
new_counts = Idea.idea_counts(discussion_id, post_id, user_id)
return {
"ok": True,
"ideas": [
{
"@id": Idea.uri_generic(idea_id),
"@type": db.query(Idea).get(idea_id).external_typename(),
"num_posts": total_posts,
"num_read_posts": read_posts,
}
for (idea_id, total_posts, read_posts) in new_counts
],
}