コード例 #1
0
ファイル: models.py プロジェクト: gusbakker/bootcamp
def notify_comment(**kwargs):  # pragma: no cover
    """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
    create_notification_handler(
        actor, receiver, Notification.COMMENTED, action_object=obj
    )
コード例 #2
0
ファイル: test_models.py プロジェクト: gusbakker/bootcamp
 def test_single_notification(self):
     Notification.objects.mark_all_as_read()
     obj = News.objects.create(user=self.user,
                               content="This is a short content.")
     create_notification_handler(self.user,
                                 self.other_user,
                                 "C",
                                 action_object=obj)
     assert Notification.objects.unread().count() == 1
コード例 #3
0
ファイル: views.py プロジェクト: gusbakker/bootcamp
def follow_user(request, user_id):
    """
    Ajax call to follow a user.
    """
    user = get_object_or_404(User, id=user_id)
    if request.user in user.followers.all():
        user.followers.remove(request.user)
        text = 'Follow'
    else:
        user.followers.add(request.user)
        create_notification_handler(request.user,
                                    user,
                                    Notification.FOLLOW,
                                    key="social_update")
        text = 'Unfollow'
    return HttpResponse(text)
コード例 #4
0
ファイル: views.py プロジェクト: gusbakker/bootcamp
def send_message_request(request, user_id):
    """
    Ajax call to send a message request.
    """
    receiver = get_object_or_404(User, id=user_id)
    contacter = request.user

    if contacter in receiver.pending_list.all():
        receiver.pending_list.remove(contacter)
        text = 'Send Request'
    else:
        receiver.pending_list.add(contacter)
        create_notification_handler(contacter,
                                    receiver,
                                    Notification.FRIEND_REQUEST,
                                    key="social_update")
        text = 'Request Sent'
    return HttpResponse(text)
コード例 #5
0
ファイル: views.py プロジェクト: gusbakker/bootcamp
def accept_message_request(request, user_id):
    """
    Ajax call to accept a message request.
    """
    sender = get_object_or_404(User, id=user_id)
    acceptor = request.user

    if sender in acceptor.pending_list.all():
        acceptor.pending_list.remove(sender)
        acceptor.contact_list.add(sender)
        sender.contact_list.add(acceptor)
        create_notification_handler(acceptor,
                                    sender,
                                    Notification.FRIEND_ACCEPT,
                                    key="social_update")

        text = 'Added to contact list'
    else:
        text = 'Unexpected error!'
    return HttpResponse(text)
コード例 #6
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 text: String with the reply.
        """
        parent = self.get_parent()
        reply_news = News.objects.create(
            user=user, content=text, reply=True, parent=parent
        )
        if self.user != user:
            create_notification_handler(
                user,
                parent.user,
                Notification.REPLY,
                action_object=reply_news.parent,
                id_value=str(parent.uuid_id),
                key="social_update",
            )
コード例 #7
0
 def switch_like(self, user):
     if user in self.liked.all():
         self.liked.remove(user)
         if self.user != user:
             delete_notification_handler(
                 user,
                 self.user,
                 Notification.LIKED,
                 action_object=self,
                 id_value=str(self.uuid_id),
                 key="social_update",
             )
     else:
         self.liked.add(user)
         if self.user != user:
             create_notification_handler(
                 user,
                 self.user,
                 Notification.LIKED,
                 action_object=self,
                 id_value=str(self.uuid_id),
                 key="social_update",
             )
コード例 #8
0
ファイル: test_models.py プロジェクト: gusbakker/bootcamp
 def test_list_notification(self):
     Notification.objects.mark_all_as_read()
     create_notification_handler(self.user, [self.user, self.other_user],
                                 "C")
     assert Notification.objects.unread().count() == 2
コード例 #9
0
ファイル: test_models.py プロジェクト: gusbakker/bootcamp
 def test_global_notification(self):
     Notification.objects.mark_all_as_read()
     create_notification_handler(self.user, "global", "C")
     assert Notification.objects.unread().count() == 1
コード例 #10
0
def broadcast_logout(sender, user, request, **kwargs):
    """Handler to be fired up upon user logout signal to notify all users."""
    create_notification_handler(user, "global", Notification.LOGGED_OUT)