本文整理汇总了Python中osf.models.Comment.find_n_unread方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.find_n_unread方法的具体用法?Python Comment.find_n_unread怎么用?Python Comment.find_n_unread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf.models.Comment
的用法示例。
在下文中一共展示了Comment.find_n_unread方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_unread_new_comments
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def test_find_unread_new_comments(self):
project = ProjectFactory()
user = UserFactory()
project.add_contributor(user, save=True)
CommentFactory(node=project, user=project.creator)
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 1
示例2: get_paginated_response
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def get_paginated_response(self, data):
"""Add number of unread comments to links.meta when viewing list of comments filtered by
a target node, file or wiki page."""
response = super(CommentPagination, self).get_paginated_response(data)
response_dict = response.data
kwargs = self.request.parser_context['kwargs'].copy()
if self.request.query_params.get('related_counts', False):
target_id = self.request.query_params.get('filter[target]', None)
node_id = kwargs.get('node_id', None)
node = Node.load(node_id)
user = self.request.user
if target_id and not user.is_anonymous and node.is_contributor(user):
root_target = Guid.load(target_id)
if root_target:
page = getattr(root_target.referent, 'root_target_page', None)
if page:
if not len(data):
unread = 0
else:
unread = Comment.find_n_unread(user=user, node=node, page=page, root_id=target_id)
if self.request.version < '2.1':
response_dict['links']['meta']['unread'] = unread
else:
response_dict['meta']['unread'] = unread
return Response(response_dict)
示例3: get_unread_comments_count
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def get_unread_comments_count(self, obj):
user = get_user_auth(self.context['request']).user
node_comments = Comment.find_n_unread(user=user, node=obj, page='node')
return {
'node': node_comments
}
示例4: test_find_unread_does_not_include_deleted_comments
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def test_find_unread_does_not_include_deleted_comments(self):
project = ProjectFactory()
user = AuthUserFactory()
project.add_contributor(user)
project.save()
CommentFactory(node=project, user=project.creator, is_deleted=True)
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 0
示例5: test_find_unread_includes_comment_replies
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def test_find_unread_includes_comment_replies(self):
project = ProjectFactory()
user = UserFactory()
project.add_contributor(user, save=True)
comment = CommentFactory(node=project, user=user)
CommentFactory(node=project, target=Guid.load(comment._id), user=project.creator)
n_unread = Comment.find_n_unread(user=user, node=project, page='node')
assert n_unread == 1
示例6: test_find_unread_is_zero_when_no_comments
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def test_find_unread_is_zero_when_no_comments(self):
n_unread = Comment.find_n_unread(user=UserFactory(), node=ProjectFactory(), page='node')
assert n_unread == 0
示例7: get_unread_comments_count
# 需要导入模块: from osf.models import Comment [as 别名]
# 或者: from osf.models.Comment import find_n_unread [as 别名]
def get_unread_comments_count(self, obj):
user = self.context['request'].user
if user.is_anonymous:
return 0
return Comment.find_n_unread(user=user, node=obj.node, page='files', root_id=obj.get_guid()._id)