Esempio n. 1
0
    def reply_this(self, user, text):
        """Handler function to create a News instance as a reply to any
        published news.

        :requires:

        :param user: The logged in user who is doing the reply.
        :param content: String with the reply.
        """
        parent = self.get_parent()
        # reply_news = News.objects.create(
        #     user=user, content=text, reply=True, parent=parent
        # )
        reply_community = Community.objects.create(
            user=user, content=text, reply=True, parent=parent
        )
        notification_handler(
            user,
            parent.user,
            Notification.REPLY,
            # action_object=reply_news,
            action_object=reply_community,
            id_value=str(parent.uuid_id),
            key="social_update_community",
        )
Esempio n. 2
0
 def test_single_notification(self):
     Notification.objects.mark_all_as_read()
     obj = News.objects.create(
         user=self.user,
         content="This is a short content."
     )
     notification_handler(self.user, self.other_user, "C", action_object=obj)
     assert Notification.objects.unread().count() == 1
Esempio n. 3
0
    def switch_like(self, user):
        if user in self.liked.all():
            self.liked.remove(user)

        else:
            self.liked.add(user)
            notification_handler(user, self.user,
                                 Notification.LIKED, action_object=self,
                                 id_value=str(self.uuid_id),
                                 key='social_update')
Esempio n. 4
0
def notify_comment(**kwargs):
    """Handler to be fired up upon comments signal to notify the author of a
    given article."""
    actor = kwargs['request'].user
    receiver = kwargs['comment'].content_object.user
    obj = kwargs['comment'].content_object
    notification_handler(actor,
                         receiver,
                         Notification.COMMENTED,
                         action_object=obj)
Esempio n. 5
0
    def switch_like(self, user):
        if user in self.liked.all():
            self.liked.remove(user)

        else:
            self.liked.add(user)
            notification_handler(user, self.user,
                                 Notification.LIKED, action_object=self,
                                 id_value=str(self.uuid_id),
                                 key='social_update')
Esempio n. 6
0
 def reply_this(self, user, text):
     parent = self.get_parent()
     reply_news = News.objects.create(
         user=user,
         content=text,
         reply=True,
         parent=parent
     )
     notification_handler(
         user, parent.user, Notification.REPLY, action_object=reply_news,
         id_value=str(parent.uuid_id), key='social_update')
Esempio n. 7
0
    def switch_attend(self, user):
        if user in self.attended.all():
            self.attended.remove(user)

        else:
            self.attended.add(user)
            notification_handler(
                user,
                self.user,
                Notification.ATTENDED,
                action_object=self,
                id_value=str(self.uuid_id),
                key="social_update",
            )
Esempio n. 8
0
    def switch_like(self, user):
        if user in self.liked.all():
            self.liked.remove(user)

        else:
            self.liked.add(user)
            print(type(self.content))
            print(re.search('<h5>(.*)</h5>', self.content))
            notification_handler(
                user,
                self.user,
                Notification.LIKED,
                action_object=self,
                # action_object=(re.search('<h5>(.*)</h5>',self.content)).group(1),
                id_value=str(self.uuid_id),
                key="social_update",
            )
Esempio n. 9
0
    def reply_this(self, user, text):
        """Handler function to create a News instance as a reply to any
        published news.

        :requires:

        :param user: The logged in user who is doing the reply.
        :param content: String with the reply.
        """
        parent = self.get_parent()
        reply_news = News.objects.create(
            user=user,
            content=text,
            reply=True,
            parent=parent
        )
        notification_handler(
            user, parent.user, Notification.REPLY, action_object=reply_news,
            id_value=str(parent.uuid_id), key='social_update')
Esempio n. 10
0
def broadcast_logout(sender, user, request, **kwargs):
    """Handler to be fired up upon user logout signal to notify all users."""
    notification_handler(user, "global", Notification.LOGGED_OUT)
Esempio n. 11
0
 def test_list_notification(self):
     Notification.objects.mark_all_as_read()
     notification_handler(self.user, [self.user, self.other_user], "C")
     assert Notification.objects.unread().count() == 2
Esempio n. 12
0
 def test_global_notification(self):
     Notification.objects.mark_all_as_read()
     notification_handler(self.user, "global", "C")
     assert Notification.objects.unread().count() == 1
Esempio n. 13
0
 def test_list_notification(self):
     Notification.objects.mark_all_as_read()
     notification_handler(self.user, [self.user, self.other_user], "C")
     assert Notification.objects.unread().count() == 2
Esempio n. 14
0
 def test_global_notification(self):
     Notification.objects.mark_all_as_read()
     notification_handler(self.user, "global", "C")
     assert Notification.objects.unread().count() == 1
Esempio n. 15
0
def broadcast_logout(sender, user, request, **kwargs):
    """Handler to be fired up upon user logout signal to notify all users."""
    notification_handler(user, "global", Notification.LOGGED_OUT)