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')
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')
def notify_shared(self, feed): if self.user != feed.user: Notification(notification_type=Notification.SHARED, from_user=self.user, to_user=feed.user, feed=feed).save() self.group_notification('shared')
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')
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()
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')
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')
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')
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
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
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()
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()
def notify_liked_bis(self, feed): if self.user == feed.user: Notification(notification_type=Notification.PROCESSED_RUN, from_user=self.user, to_user=self.user, feed=feed).save()
def setUp(self): # creates a fictif user u = User() u.username = "******" u.password = "******" u.save() # create an activity related to that user activity = Activity() activity.user = u activity.activity_type = "Favorite" activity.date = timezone.now() # check we can save it to the database activity.save() # creates two fictif users u1 = User() u1.username = "******" u1.password = "******" u1.save() u2 = User() u2.username = "******" u2.password = "******" u2.save() # create one notification for each type of notification # Liked notifL = Notification() notifL.from_user = u1 notifL.to_user = u2 notifL.date = timezone.now() notifL.notification_type = 'Liked' # this is a like # save it to the database notifL.save() # Commented notifC = Notification() notifC.from_user = u1 notifC.to_user = u2 notifC.date = timezone.now() notifC.notification_type = 'Commented' # save it to the database notifC.save() # Favorited notifF = Notification() notifF.from_user = u1 notifF.to_user = u2 notifF.date = timezone.now() notifF.notification_type = 'Favorited' # save it to the database notifF.save() # Answered notifA = Notification() notifA.from_user = u1 notifA.to_user = u2 notifA.date = timezone.now() notifA.notification_type = 'Answered' # save it to the database notifA.save() # Accepted answer notifW = Notification() notifW.from_user = u1 notifW.to_user = u2 notifW.date = timezone.now() notifW.notification_type = 'Accepted Answer' # save it to the database notifW.save() # Edited article notifE = Notification() notifE.from_user = u1 notifE.to_user = u2 notifE.date = timezone.now() notifE.notification_type = 'Edited Article' # save it to the database notifE.save() # Also commented notifS = Notification() notifS.from_user = u1 notifS.to_user = u2 notifS.date = timezone.now() notifS.notification_type = 'Also Commented' # save it to the database notifS.save()
def last_notifications(request): user = request.user notifications = Notification.call_latest_notifications(user) return render(request, 'activities/last_notifications.html', {'notifications': notifications})
def setUp(self): # creates a fictif user u = User() u.username = "******" u.password = "******" u.save() # create an activity related to that user activity = Activity() activity.user = u activity.activity_type = "Favorite" activity.date = timezone.now() # check we can save it to the database activity.save() # creates two fictif users u1 = User() u1.username = "******" u1.password = "******" u1.save() u2 = User() u2.username = "******" u2.password = "******" u2.save() # create one notification for each type of notification # Liked notifL = Notification() notifL.from_user = u1 notifL.to_user = u2 notifL.date = timezone.now() notifL.notification_type = 'Liked' # this is a like # save it to the database notifL.save() # Commented notifC = Notification() notifC.from_user = u1 notifC.to_user = u2 notifC.date = timezone.now() notifC.notification_type = 'Commented' # save it to the database notifC.save() # Favorited notifF = Notification() notifF.from_user = u1 notifF.to_user = u2 notifF.date = timezone.now() notifF.notification_type = 'Favorited' # save it to the database notifF.save() # Answered notifA = Notification() notifA.from_user = u1 notifA.to_user = u2 notifA.date = timezone.now() notifA.notification_type = 'Answered' # save it to the database notifA.save() # Accepted answer notifW = Notification() notifW.from_user = u1 notifW.to_user = u2 notifW.date = timezone.now() notifW.notification_type = 'Accepted Answer' # save it to the database notifW.save() # Edited article notifE = Notification() notifE.from_user = u1 notifE.to_user = u2 notifE.date = timezone.now() notifE.notification_type = 'Edited Article' # save it to the database notifE.save() # Also commented notifS = Notification() notifS.from_user = u1 notifS.to_user = u2 notifS.date = timezone.now() notifS.notification_type = 'Also Commented' # save it to the database notifS.save()
def notify_job_done(self, algo): if self.user == algo.user: Notification(notification_type=Notification.PROCESSED_RUN, from_user=self.user, to_user=self.user, feed=algo).save()