Exemplo n.º 1
0
    def notify_upvoted_question(self, question):
        if self.user != question.user:
            Notification(notification_type=Notification.UPVOTED_Q,
                         from_user=self.user,
                         to_user=question.user,
                         question=question).save()

        self.group_notification('upvoted_question')
Exemplo n.º 2
0
    def notify_upvoted_answer(self, answer):
        if self.user != answer.user:
            Notification(notification_type=Notification.UPVOTED_A,
                         from_user=self.user,
                         to_user=answer.user,
                         answer=answer).save()

        self.group_notification('upvoted_answer')
Exemplo n.º 3
0
    def notify_accepted(self, answer):
        if self.user != answer.user:
            Notification(notification_type=Notification.ACCEPTED_ANSWER,
                         from_user=self.user,
                         to_user=answer.user,
                         answer=answer).save()

        self.group_notification('accepted_answer')
Exemplo n.º 4
0
    def notify_answered(self, question):
        if self.user != question.user:
            Notification(notification_type=Notification.ANSWERED,
                         from_user=self.user,
                         to_user=question.user,
                         question=question).save()

        self.group_notification('answered')
Exemplo n.º 5
0
    def notify_favorited(self, question):
        if self.user != question.user:
            Notification(notification_type=Notification.FAVORITED,
                         from_user=self.user,
                         to_user=question.user,
                         question=question).save()

        self.group_notification('favorited')
Exemplo n.º 6
0
    def notify_commented(self, feed):
        if self.user != feed.user:
            Notification(notification_type=Notification.COMMENTED,
                         from_user=self.user,
                         to_user=feed.user,
                         feed=feed).save()

        self.group_notification('commented')
        feed.feed_log('commented')
Exemplo n.º 7
0
    def notify_liked(self, feed):
        if self.user != feed.user:
            Notification(notification_type=Notification.LIKED,
                         from_user=self.user,
                         to_user=feed.user,
                         feed=feed).save()

        self.group_notification('liked')
        feed.feed_log('liked')
Exemplo n.º 8
0
 def test_upvote_answer_notification(self):
     Profile.objects.get(
         user=self.other_user).notify_upvoted_answer(self.answer)
     notification = Notification.objects.get(answer=self.answer)
     test_string = Notification._UPVOTED_ANSWER_TEMPLATE.format(
         self.other_user.username,
         self.other_user.profile.get_screen_name(),
         self.answer.pk,
         Notification.get_summary(notification, self.answer.description)
     )
     assert isinstance(notification, Notification)
     assert str(notification) == test_string
Exemplo n.º 9
0
 def test_upvote_question_notification(self):
     Profile.objects.get(
         user=self.other_user).notify_upvoted_question(self.question)
     notification = Notification.objects.get(question=self.question)
     test_string = Notification._UPVOTED_QUESTION_TEMPLATE.format(
         self.other_user.username,
         self.other_user.profile.get_screen_name(),
         self.question.pk,
         Notification.get_summary(notification, self.question.title)
     )
     assert isinstance(notification, Notification)
     assert str(notification) == test_string
Exemplo n.º 10
0
    def notify_also_commented(self, feed):
        comments = feed.get_comments()
        users = []
        for comment in comments:
            if comment.user != self.user and comment.user != feed.user:
                users.append(comment.user.pk)

        users = list(set(users))
        for user in users:
            Notification(notification_type=Notification.ALSO_COMMENTED,
                         from_user=self.user,
                         to_user=User(id=user),
                         feed=feed).save()
Exemplo n.º 11
0
def last_notifications(request):
    user = request.user
    notifications = Notification.call_latest_notifications(user)
    return render(request, 'activities/last_notifications.html',
                  {'notifications': notifications})