当前位置: 首页>>代码示例>>Python>>正文


Python services.remove_watcher函数代码示例

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


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

示例3: 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

示例4: unwatch

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

示例5: remove_watcher

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


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