• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python services.add_watcher函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中taiga.projects.notifications.services.add_watcher函数的典型用法代码示例。如果您正苦于以下问题:Python add_watcher函数的具体用法?Python add_watcher怎么用?Python add_watcher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add_watcher函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: restore_object

    def restore_object(self, attrs, instance=None):
        #watchers is not a field from the model but can be attached in the get_queryset of the viewset.
        #If that's the case we need to remove it before calling the super method
        watcher_field = self.fields.pop("watchers", None)
        self.validate_watchers(attrs, "watchers")
        new_watcher_ids = set(attrs.pop("watchers", []))
        obj = super(WatchedResourceModelSerializer, self).restore_object(attrs, instance)

        #A partial update can exclude the watchers field or if the new instance can still not be saved
        if instance is None or len(new_watcher_ids) == 0:
            return obj

        old_watcher_ids = set(obj.get_watchers().values_list("id", flat=True))
        adding_watcher_ids = list(new_watcher_ids.difference(old_watcher_ids))
        removing_watcher_ids = list(old_watcher_ids.difference(new_watcher_ids))

        User = apps.get_model("users", "User")
        adding_users = User.objects.filter(id__in=adding_watcher_ids)
        removing_users = User.objects.filter(id__in=removing_watcher_ids)
        for user in adding_users:
            services.add_watcher(obj, user)

        for user in removing_users:
            services.remove_watcher(obj, user)

        obj.watchers = obj.get_watchers()

        return obj
开发者ID:heyox,项目名称:taiga-back,代码行数:28,代码来源:mixins.py


示例2: test_userstory_watchers_retrieve

def test_userstory_watchers_retrieve(client, data):
    add_watcher(data.public_user_story, data.project_owner)
    public_url = reverse('userstory-watchers-detail', kwargs={"resource_id": data.public_user_story.pk,
                                                            "pk": data.project_owner.pk})
    add_watcher(data.private_user_story1, data.project_owner)
    private_url1 = reverse('userstory-watchers-detail', kwargs={"resource_id": data.private_user_story1.pk,
                                                              "pk": data.project_owner.pk})
    add_watcher(data.private_user_story2, data.project_owner)
    private_url2 = reverse('userstory-watchers-detail', kwargs={"resource_id": data.private_user_story2.pk,
                                                              "pk": data.project_owner.pk})
    add_watcher(data.blocked_user_story, data.project_owner)
    blocked_url = reverse('userstory-watchers-detail', kwargs={"resource_id": data.blocked_user_story.pk,
                                                              "pk": data.project_owner.pk})

    users = [
        None,
        data.registered_user,
        data.project_member_without_perms,
        data.project_member_with_perms,
        data.project_owner
    ]

    results = helper_test_http_method(client, 'get', public_url, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, 'get', private_url1, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, 'get', private_url2, None, users)
    assert results == [401, 403, 403, 200, 200]
    results = helper_test_http_method(client, 'get', blocked_url, None, users)
    assert results == [401, 403, 403, 200, 200]
开发者ID:CrypticGator,项目名称:taiga-back,代码行数:30,代码来源:test_userstories_resources.py


示例3: test_wikipage_watchers_retrieve

def test_wikipage_watchers_retrieve(client, data):
    add_watcher(data.public_wiki_page, data.project_owner)
    public_url = reverse(
        "wiki-watchers-detail", kwargs={"resource_id": data.public_wiki_page.pk, "pk": data.project_owner.pk}
    )
    add_watcher(data.private_wiki_page1, data.project_owner)
    private_url1 = reverse(
        "wiki-watchers-detail", kwargs={"resource_id": data.private_wiki_page1.pk, "pk": data.project_owner.pk}
    )
    add_watcher(data.private_wiki_page2, data.project_owner)
    private_url2 = reverse(
        "wiki-watchers-detail", kwargs={"resource_id": data.private_wiki_page2.pk, "pk": data.project_owner.pk}
    )
    add_watcher(data.blocked_wiki_page, data.project_owner)
    blocked_url = reverse(
        "wiki-watchers-detail", kwargs={"resource_id": data.blocked_wiki_page.pk, "pk": data.project_owner.pk}
    )
    users = [
        None,
        data.registered_user,
        data.project_member_without_perms,
        data.project_member_with_perms,
        data.project_owner,
    ]

    results = helper_test_http_method(client, "get", public_url, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, "get", private_url1, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, "get", private_url2, None, users)
    assert results == [401, 403, 403, 200, 200]
    results = helper_test_http_method(client, "get", blocked_url, None, users)
    assert results == [401, 403, 403, 200, 200]
开发者ID:a06kin,项目名称:taiga-back,代码行数:33,代码来源:test_wiki_resources.py


示例4: save_watchers

    def save_watchers(self):
        new_watcher_emails = set(self._watchers)
        old_watcher_emails = set(self.object.get_watchers().values_list("email", flat=True))
        adding_watcher_emails = list(new_watcher_emails.difference(old_watcher_emails))
        removing_watcher_emails = list(old_watcher_emails.difference(new_watcher_emails))

        User = apps.get_model("users", "User")
        adding_users = User.objects.filter(email__in=adding_watcher_emails)
        removing_users = User.objects.filter(email__in=removing_watcher_emails)

        for user in adding_users:
            notifications_services.add_watcher(self.object, user)

        for user in removing_users:
            notifications_services.remove_watcher(self.object, user)

        self.object.watchers = [user.email for user in self.object.get_watchers()]
开发者ID:andrewchenshx,项目名称:taiga-back,代码行数:17,代码来源:serializers.py


示例5: restore_object

    def restore_object(self, attrs, instance=None):
        #watchers is not a field from the model but can be attached in the get_queryset of the viewset.
        #If that's the case we need to remove it before calling the super method
        watcher_field = self.fields.pop("watchers", None)
        instance = super(WatchedResourceModelSerializer, self).restore_object(attrs, instance)
        if instance is not None and self.validate_watchers(attrs, "watchers"):
            new_watcher_ids = set(attrs.get("watchers", []))
            old_watcher_ids = set(services.get_watchers(instance).values_list("id", flat=True))
            adding_watcher_ids = list(new_watcher_ids.difference(old_watcher_ids))
            removing_watcher_ids = list(old_watcher_ids.difference(new_watcher_ids))

            User = apps.get_model("users", "User")
            adding_users = User.objects.filter(id__in=adding_watcher_ids)
            removing_users = User.objects.filter(id__in=removing_watcher_ids)
            for user in adding_users:
                services.add_watcher(instance, user)

            for user in removing_users:
                services.remove_watcher(instance, user)

            instance.watchers = services.get_watchers(instance)

        return instance
开发者ID:Davidx7,项目名称:taiga-back,代码行数:23,代码来源:mixins.py


示例6: watch

 def watch(self, request, pk=None):
     obj = self.get_object()
     self.check_permissions(request, "watch", obj)
     services.add_watcher(obj, request.user)
     return response.Ok()
开发者ID:heyox,项目名称:taiga-back,代码行数:5,代码来源:mixins.py


示例7: add_watcher

 def add_watcher(self, user):
     services.add_watcher(self, user)
开发者ID:heyox,项目名称:taiga-back,代码行数:2,代码来源:mixins.py



注:本文中的taiga.projects.notifications.services.add_watcher函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python services.analize_object_for_watchers函数代码示例发布时间:2022-05-27
下一篇:
Python services.take_snapshot函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap