We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Notification permanante
Bonjour,

Depuis le forum, 

> Je me suis désabonné à un sujet (ne plus suivre) alors que j'avais une notification de se sujet.
> 
> Désormais j'ai en permanence 1 notification. Même si je me réabonne, elle ne disparaît plus ^^"
> Ce bug se combine également avec celui-ci [[v18] Date incorrecte dans les notifications](https://github.com/zestedesavoir/zds-site/issues/3628) .
> 
> D'ailleurs on peut voir ce bug comme l'opposé de celui-ci [Suivre un sujet, messages oubliés](https://github.com/zestedesavoir/zds-site/issues/3654) ».
> 
> Source: [ache](https://zestedesavoir.com/forums/sujet/6300/notification-permanante/)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zds/notification/managers.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from django.contrib.contenttypes.models import ContentType
3 from django.core.exceptions import ObjectDoesNotExist
4 from django.db import models
5 
6 from zds.forum.models import Topic
7 from zds.utils import get_current_user
8 
9 
10 class SubscriptionManager(models.Manager):
11     """
12     Custom subscription manager
13     """
14 
15     def get_existing(self, user, content_object, is_active=None, by_email=None):
16         """
17         If exists, return the existing subscription for the given user and content object.
18 
19         :param user: concerned user.
20         :type user: django.contrib.auth.models.User
21         :param content_object: Generic content concerned.
22         :type content_object: instance concerned by notifications
23         :param is_active: Boolean to know if we want a subscription active or not.
24         :type is_active: Boolean
25         :param by_email: Boolean to know if we want a subscription for email or not.
26         :type by_email: Boolean
27         :return: subscription or None
28         """
29         content_type = ContentType.objects.get_for_model(content_object)
30         try:
31             if is_active is None and by_email is None:
32                 existing = self.get(
33                     object_id=content_object.pk,
34                     content_type__pk=content_type.pk,
35                     user=user)
36             elif is_active is not None and by_email is None:
37                 existing = self.get(
38                     object_id=content_object.pk,
39                     content_type__pk=content_type.pk,
40                     user=user, is_active=is_active)
41             elif is_active is None and by_email is not None:
42                 existing = self.get(
43                     object_id=content_object.pk,
44                     content_type__pk=content_type.pk,
45                     user=user, by_email=by_email)
46             else:
47                 existing = self.get(
48                     object_id=content_object.pk,
49                     content_type__pk=content_type.pk,
50                     user=user, is_active=is_active,
51                     by_email=by_email)
52         except ObjectDoesNotExist:
53             existing = None
54         return existing
55 
56     def get_or_create_active(self, user, content_object):
57         """
58         Gets (or create if it doesn't exist) the subscription for the content object given.
59 
60         :param user: concerned user.
61         :type user: django.contrib.auth.models.User
62         :param content_object: Generic content concerned.
63         :type content_object: instance concerned by notifications
64         :return: subscription
65         """
66         content_type = ContentType.objects.get_for_model(content_object)
67         try:
68             subscription = self.get(
69                 object_id=content_object.pk,
70                 content_type__pk=content_type.pk,
71                 user=user)
72             if not subscription.is_active:
73                 subscription.activate()
74         except ObjectDoesNotExist:
75             subscription = self.model(user=user, content_object=content_object)
76             subscription.save()
77 
78         return subscription
79 
80     def get_subscriptions(self, content_object, is_active=True):
81         """
82         Gets subscriptions of the content object.
83 
84         :param content_object: Generic content concerned.
85         :type content_object: instance concerned by notifications
86         :param is_active: Boolean to know if we want a subscription active or not.
87         :type is_active: Boolean
88         :return: an iterable list of subscriptions
89         """
90         content_type = ContentType.objects.get_for_model(content_object)
91         return self.filter(object_id=content_object.pk,
92                            content_type__pk=content_type.pk,
93                            is_active=is_active)
94 
95     def get_subscribers(self, content_object, only_by_email=False):
96         """
97         Gets all subscribers of a content object.
98 
99         :param content_object: Generic content concerned.
100         :type content_object: instance concerned by notifications
101         :param only_by_email: Boolean to know if we want a subscription for email or not.
102         :type only_by_email: Boolean
103         :return: users
104         """
105         content_type = ContentType.objects.get_for_model(content_object)
106         if only_by_email:
107             # if I'm only interested by the email subscription
108             subscription_list = self.filter(
109                 object_id=content_object.pk,
110                 content_type__pk=content_type.pk,
111                 by_email=True)
112         else:
113             subscription_list = self.filter(
114                 object_id=content_object.pk,
115                 content_type__pk=content_type.pk)
116 
117         return [subscription.user for subscription in subscription_list]
118 
119     def toggle_follow(self, content_object, user=None, by_email=False):
120         """
121         Toggle following of a resource notifiable for a user.
122 
123         :param content_object: A resource notifiable.
124         :param user: A user. If undefined, the current user is used.
125         :param by_email: Get subscription by email or not.
126         :return: subscription of the user for the content.
127         """
128         if not user:
129             user = get_current_user()
130         if by_email:
131             existing = self.get_existing(user, content_object, is_active=True, by_email=True)
132         else:
133             existing = self.get_existing(user, content_object, is_active=True)
134         if not existing:
135             subscription = self.get_or_create_active(user, content_object)
136             if by_email:
137                 subscription.activate_email()
138             return subscription
139         if by_email:
140             existing.deactivate_email()
141         else:
142             existing.deactivate()
143         return existing
144 
145 
146 class TopicAnswerSubscriptionManager(SubscriptionManager):
147     """
148     Custom topic answer subscription manager.
149     """
150 
151     def get_objects_followed_by(self, user):
152         """
153         Gets objects followed by the given user.
154 
155         :param user: concerned user.
156         :type user: django.contrib.auth.models.User
157         :return: All objects followed by given user.
158         """
159         topic_list = self.filter(user=user, is_active=True, content_type=ContentType.objects.get_for_model(Topic)) \
160             .values_list('object_id', flat=True)
161 
162         return Topic.objects.filter(id__in=topic_list).order_by('-last_message__pubdate')
163 
164     def unfollow_and_mark_read_everybody_at(self, topic):
165         """
166         Deactivate a subscription at a topic and mark read the notification associated if exist.
167 
168         :param topic: topic concerned.
169         :type topic: zds.forum.models.Topic
170         """
171         subscriptions = self.get_subscriptions(topic)
172         for subscription in subscriptions:
173             if not topic.forum.can_read(subscription.user):
174                 subscription.deactivate()
175                 subscription.mark_notification_read()
176 
177 
178 class NotificationManager(models.Manager):
179     """
180     Custom notification manager.
181     """
182 
183     def get_unread_notifications_of(self, user):
184         """
185         Gets all notifications for a user whose user is passed as argument.
186 
187         :param user: user object
188         :type user: django.contrib.auth.models.User
189         :return: an iterable over notifications with user data already loaded
190         :rtype: an iterable list of notifications
191         """
192         return self.filter(subscription__user=user, is_read=False) \
193             .select_related("sender")
194 
195     def filter_content_type_of(self, model):
196         """
197         Applies a filter on the content_type.
198 
199         :param model: Model concerned for the ContentType
200         :type model: Model concerned by notifications
201         :return: an iterable list of notifications
202         """
203         content_subscription_type = ContentType.objects.get_for_model(model)
204         return self.filter(subscription__content_type__pk=content_subscription_type.pk)
205 
206     def get_users_for_unread_notification_on(self, content_object):
207         """
208         Gets all users who have an notification unread on the given content object.
209 
210         :param content_object: generic content object.
211         :type content_object: instance concerned by notifications
212         :return: an iterable list of users.
213         """
214         content_type = ContentType.objects.get_for_model(content_object)
215         notifications = self.filter(object_id=content_object.pk, content_type__pk=content_type.pk) \
216             .select_related("subscription") \
217             .select_related("subscription__user")
218         return [notification.subscription.user for notification in notifications]
219 
220 
221 class TopicFollowedManager(models.Manager):
222     def get_followers_by_email(self, topic):
223         """
224         :return: the set of users who follow this topic by email.
225         """
226         return self.filter(topic=topic, email=True).select_related("user")
227 
228     def is_followed(self, topic, user=None):
229         """
230         Checks if the user follows this topic.
231         :param user: A user. If undefined, the current user is used.
232         :return: `True` if the user follows this topic, `False` otherwise.
233         """
234         if user is None:
235             user = get_current_user()
236 
237         return self.filter(topic=topic, user=user).exists()
238
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zds/notification/managers.py b/zds/notification/managers.py
--- a/zds/notification/managers.py
+++ b/zds/notification/managers.py
@@ -4,6 +4,7 @@
 from django.db import models
 
 from zds.forum.models import Topic
+from zds.notification import signals
 from zds.utils import get_current_user
 
 
@@ -136,6 +137,7 @@
             if by_email:
                 subscription.activate_email()
             return subscription
+        signals.content_read.send(sender=content_object.__class__, instance=content_object, user=user)
         if by_email:
             existing.deactivate_email()
         else:

{"golden_diff": "diff --git a/zds/notification/managers.py b/zds/notification/managers.py\n--- a/zds/notification/managers.py\n+++ b/zds/notification/managers.py\n@@ -4,6 +4,7 @@\n from django.db import models\n \n from zds.forum.models import Topic\n+from zds.notification import signals\n from zds.utils import get_current_user\n \n \n@@ -136,6 +137,7 @@\n             if by_email:\n                 subscription.activate_email()\n             return subscription\n+        signals.content_read.send(sender=content_object.__class__, instance=content_object, user=user)\n         if by_email:\n             existing.deactivate_email()\n         else:\n", "issue": "Notification permanante\nBonjour,\n\nDepuis le forum, \n\n> Je me suis d\u00e9sabonn\u00e9 \u00e0 un sujet (ne plus suivre) alors que j'avais une notification de se sujet.\n> \n> D\u00e9sormais j'ai en permanence 1 notification. M\u00eame si je me r\u00e9abonne, elle ne dispara\u00eet plus ^^\"\n> Ce bug se combine \u00e9galement avec celui-ci [[v18] Date incorrecte dans les notifications](https://github.com/zestedesavoir/zds-site/issues/3628) .\n> \n> D'ailleurs on peut voir ce bug comme l'oppos\u00e9 de celui-ci [Suivre un sujet, messages oubli\u00e9s](https://github.com/zestedesavoir/zds-site/issues/3654) \u00bb.\n> \n> Source: [ache](https://zestedesavoir.com/forums/sujet/6300/notification-permanante/)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.core.exceptions import ObjectDoesNotExist\nfrom django.db import models\n\nfrom zds.forum.models import Topic\nfrom zds.utils import get_current_user\n\n\nclass SubscriptionManager(models.Manager):\n    \"\"\"\n    Custom subscription manager\n    \"\"\"\n\n    def get_existing(self, user, content_object, is_active=None, by_email=None):\n        \"\"\"\n        If exists, return the existing subscription for the given user and content object.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param is_active: Boolean to know if we want a subscription active or not.\n        :type is_active: Boolean\n        :param by_email: Boolean to know if we want a subscription for email or not.\n        :type by_email: Boolean\n        :return: subscription or None\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        try:\n            if is_active is None and by_email is None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user)\n            elif is_active is not None and by_email is None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, is_active=is_active)\n            elif is_active is None and by_email is not None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, by_email=by_email)\n            else:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, is_active=is_active,\n                    by_email=by_email)\n        except ObjectDoesNotExist:\n            existing = None\n        return existing\n\n    def get_or_create_active(self, user, content_object):\n        \"\"\"\n        Gets (or create if it doesn't exist) the subscription for the content object given.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :return: subscription\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        try:\n            subscription = self.get(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk,\n                user=user)\n            if not subscription.is_active:\n                subscription.activate()\n        except ObjectDoesNotExist:\n            subscription = self.model(user=user, content_object=content_object)\n            subscription.save()\n\n        return subscription\n\n    def get_subscriptions(self, content_object, is_active=True):\n        \"\"\"\n        Gets subscriptions of the content object.\n\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param is_active: Boolean to know if we want a subscription active or not.\n        :type is_active: Boolean\n        :return: an iterable list of subscriptions\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        return self.filter(object_id=content_object.pk,\n                           content_type__pk=content_type.pk,\n                           is_active=is_active)\n\n    def get_subscribers(self, content_object, only_by_email=False):\n        \"\"\"\n        Gets all subscribers of a content object.\n\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param only_by_email: Boolean to know if we want a subscription for email or not.\n        :type only_by_email: Boolean\n        :return: users\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        if only_by_email:\n            # if I'm only interested by the email subscription\n            subscription_list = self.filter(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk,\n                by_email=True)\n        else:\n            subscription_list = self.filter(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk)\n\n        return [subscription.user for subscription in subscription_list]\n\n    def toggle_follow(self, content_object, user=None, by_email=False):\n        \"\"\"\n        Toggle following of a resource notifiable for a user.\n\n        :param content_object: A resource notifiable.\n        :param user: A user. If undefined, the current user is used.\n        :param by_email: Get subscription by email or not.\n        :return: subscription of the user for the content.\n        \"\"\"\n        if not user:\n            user = get_current_user()\n        if by_email:\n            existing = self.get_existing(user, content_object, is_active=True, by_email=True)\n        else:\n            existing = self.get_existing(user, content_object, is_active=True)\n        if not existing:\n            subscription = self.get_or_create_active(user, content_object)\n            if by_email:\n                subscription.activate_email()\n            return subscription\n        if by_email:\n            existing.deactivate_email()\n        else:\n            existing.deactivate()\n        return existing\n\n\nclass TopicAnswerSubscriptionManager(SubscriptionManager):\n    \"\"\"\n    Custom topic answer subscription manager.\n    \"\"\"\n\n    def get_objects_followed_by(self, user):\n        \"\"\"\n        Gets objects followed by the given user.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :return: All objects followed by given user.\n        \"\"\"\n        topic_list = self.filter(user=user, is_active=True, content_type=ContentType.objects.get_for_model(Topic)) \\\n            .values_list('object_id', flat=True)\n\n        return Topic.objects.filter(id__in=topic_list).order_by('-last_message__pubdate')\n\n    def unfollow_and_mark_read_everybody_at(self, topic):\n        \"\"\"\n        Deactivate a subscription at a topic and mark read the notification associated if exist.\n\n        :param topic: topic concerned.\n        :type topic: zds.forum.models.Topic\n        \"\"\"\n        subscriptions = self.get_subscriptions(topic)\n        for subscription in subscriptions:\n            if not topic.forum.can_read(subscription.user):\n                subscription.deactivate()\n                subscription.mark_notification_read()\n\n\nclass NotificationManager(models.Manager):\n    \"\"\"\n    Custom notification manager.\n    \"\"\"\n\n    def get_unread_notifications_of(self, user):\n        \"\"\"\n        Gets all notifications for a user whose user is passed as argument.\n\n        :param user: user object\n        :type user: django.contrib.auth.models.User\n        :return: an iterable over notifications with user data already loaded\n        :rtype: an iterable list of notifications\n        \"\"\"\n        return self.filter(subscription__user=user, is_read=False) \\\n            .select_related(\"sender\")\n\n    def filter_content_type_of(self, model):\n        \"\"\"\n        Applies a filter on the content_type.\n\n        :param model: Model concerned for the ContentType\n        :type model: Model concerned by notifications\n        :return: an iterable list of notifications\n        \"\"\"\n        content_subscription_type = ContentType.objects.get_for_model(model)\n        return self.filter(subscription__content_type__pk=content_subscription_type.pk)\n\n    def get_users_for_unread_notification_on(self, content_object):\n        \"\"\"\n        Gets all users who have an notification unread on the given content object.\n\n        :param content_object: generic content object.\n        :type content_object: instance concerned by notifications\n        :return: an iterable list of users.\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        notifications = self.filter(object_id=content_object.pk, content_type__pk=content_type.pk) \\\n            .select_related(\"subscription\") \\\n            .select_related(\"subscription__user\")\n        return [notification.subscription.user for notification in notifications]\n\n\nclass TopicFollowedManager(models.Manager):\n    def get_followers_by_email(self, topic):\n        \"\"\"\n        :return: the set of users who follow this topic by email.\n        \"\"\"\n        return self.filter(topic=topic, email=True).select_related(\"user\")\n\n    def is_followed(self, topic, user=None):\n        \"\"\"\n        Checks if the user follows this topic.\n        :param user: A user. If undefined, the current user is used.\n        :return: `True` if the user follows this topic, `False` otherwise.\n        \"\"\"\n        if user is None:\n            user = get_current_user()\n\n        return self.filter(topic=topic, user=user).exists()\n", "path": "zds/notification/managers.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.core.exceptions import ObjectDoesNotExist\nfrom django.db import models\n\nfrom zds.forum.models import Topic\nfrom zds.notification import signals\nfrom zds.utils import get_current_user\n\n\nclass SubscriptionManager(models.Manager):\n    \"\"\"\n    Custom subscription manager\n    \"\"\"\n\n    def get_existing(self, user, content_object, is_active=None, by_email=None):\n        \"\"\"\n        If exists, return the existing subscription for the given user and content object.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param is_active: Boolean to know if we want a subscription active or not.\n        :type is_active: Boolean\n        :param by_email: Boolean to know if we want a subscription for email or not.\n        :type by_email: Boolean\n        :return: subscription or None\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        try:\n            if is_active is None and by_email is None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user)\n            elif is_active is not None and by_email is None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, is_active=is_active)\n            elif is_active is None and by_email is not None:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, by_email=by_email)\n            else:\n                existing = self.get(\n                    object_id=content_object.pk,\n                    content_type__pk=content_type.pk,\n                    user=user, is_active=is_active,\n                    by_email=by_email)\n        except ObjectDoesNotExist:\n            existing = None\n        return existing\n\n    def get_or_create_active(self, user, content_object):\n        \"\"\"\n        Gets (or create if it doesn't exist) the subscription for the content object given.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :return: subscription\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        try:\n            subscription = self.get(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk,\n                user=user)\n            if not subscription.is_active:\n                subscription.activate()\n        except ObjectDoesNotExist:\n            subscription = self.model(user=user, content_object=content_object)\n            subscription.save()\n\n        return subscription\n\n    def get_subscriptions(self, content_object, is_active=True):\n        \"\"\"\n        Gets subscriptions of the content object.\n\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param is_active: Boolean to know if we want a subscription active or not.\n        :type is_active: Boolean\n        :return: an iterable list of subscriptions\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        return self.filter(object_id=content_object.pk,\n                           content_type__pk=content_type.pk,\n                           is_active=is_active)\n\n    def get_subscribers(self, content_object, only_by_email=False):\n        \"\"\"\n        Gets all subscribers of a content object.\n\n        :param content_object: Generic content concerned.\n        :type content_object: instance concerned by notifications\n        :param only_by_email: Boolean to know if we want a subscription for email or not.\n        :type only_by_email: Boolean\n        :return: users\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        if only_by_email:\n            # if I'm only interested by the email subscription\n            subscription_list = self.filter(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk,\n                by_email=True)\n        else:\n            subscription_list = self.filter(\n                object_id=content_object.pk,\n                content_type__pk=content_type.pk)\n\n        return [subscription.user for subscription in subscription_list]\n\n    def toggle_follow(self, content_object, user=None, by_email=False):\n        \"\"\"\n        Toggle following of a resource notifiable for a user.\n\n        :param content_object: A resource notifiable.\n        :param user: A user. If undefined, the current user is used.\n        :param by_email: Get subscription by email or not.\n        :return: subscription of the user for the content.\n        \"\"\"\n        if not user:\n            user = get_current_user()\n        if by_email:\n            existing = self.get_existing(user, content_object, is_active=True, by_email=True)\n        else:\n            existing = self.get_existing(user, content_object, is_active=True)\n        if not existing:\n            subscription = self.get_or_create_active(user, content_object)\n            if by_email:\n                subscription.activate_email()\n            return subscription\n        signals.content_read.send(sender=content_object.__class__, instance=content_object, user=user)\n        if by_email:\n            existing.deactivate_email()\n        else:\n            existing.deactivate()\n        return existing\n\n\nclass TopicAnswerSubscriptionManager(SubscriptionManager):\n    \"\"\"\n    Custom topic answer subscription manager.\n    \"\"\"\n\n    def get_objects_followed_by(self, user):\n        \"\"\"\n        Gets objects followed by the given user.\n\n        :param user: concerned user.\n        :type user: django.contrib.auth.models.User\n        :return: All objects followed by given user.\n        \"\"\"\n        topic_list = self.filter(user=user, is_active=True, content_type=ContentType.objects.get_for_model(Topic)) \\\n            .values_list('object_id', flat=True)\n\n        return Topic.objects.filter(id__in=topic_list).order_by('-last_message__pubdate')\n\n    def unfollow_and_mark_read_everybody_at(self, topic):\n        \"\"\"\n        Deactivate a subscription at a topic and mark read the notification associated if exist.\n\n        :param topic: topic concerned.\n        :type topic: zds.forum.models.Topic\n        \"\"\"\n        subscriptions = self.get_subscriptions(topic)\n        for subscription in subscriptions:\n            if not topic.forum.can_read(subscription.user):\n                subscription.deactivate()\n                subscription.mark_notification_read()\n\n\nclass NotificationManager(models.Manager):\n    \"\"\"\n    Custom notification manager.\n    \"\"\"\n\n    def get_unread_notifications_of(self, user):\n        \"\"\"\n        Gets all notifications for a user whose user is passed as argument.\n\n        :param user: user object\n        :type user: django.contrib.auth.models.User\n        :return: an iterable over notifications with user data already loaded\n        :rtype: an iterable list of notifications\n        \"\"\"\n        return self.filter(subscription__user=user, is_read=False) \\\n            .select_related(\"sender\")\n\n    def filter_content_type_of(self, model):\n        \"\"\"\n        Applies a filter on the content_type.\n\n        :param model: Model concerned for the ContentType\n        :type model: Model concerned by notifications\n        :return: an iterable list of notifications\n        \"\"\"\n        content_subscription_type = ContentType.objects.get_for_model(model)\n        return self.filter(subscription__content_type__pk=content_subscription_type.pk)\n\n    def get_users_for_unread_notification_on(self, content_object):\n        \"\"\"\n        Gets all users who have an notification unread on the given content object.\n\n        :param content_object: generic content object.\n        :type content_object: instance concerned by notifications\n        :return: an iterable list of users.\n        \"\"\"\n        content_type = ContentType.objects.get_for_model(content_object)\n        notifications = self.filter(object_id=content_object.pk, content_type__pk=content_type.pk) \\\n            .select_related(\"subscription\") \\\n            .select_related(\"subscription__user\")\n        return [notification.subscription.user for notification in notifications]\n\n\nclass TopicFollowedManager(models.Manager):\n    def get_followers_by_email(self, topic):\n        \"\"\"\n        :return: the set of users who follow this topic by email.\n        \"\"\"\n        return self.filter(topic=topic, email=True).select_related(\"user\")\n\n    def is_followed(self, topic, user=None):\n        \"\"\"\n        Checks if the user follows this topic.\n        :param user: A user. If undefined, the current user is used.\n        :return: `True` if the user follows this topic, `False` otherwise.\n        \"\"\"\n        if user is None:\n            user = get_current_user()\n\n        return self.filter(topic=topic, user=user).exists()\n", "path": "zds/notification/managers.py"}]}