Beispiel #1
0
    def setUp(self):
        self.url = '/api/v1/feed-notifications/'

        self.user = User.objects.get(id=1)
        self.second_user = User.objects.get(id=2)
        self.article1 = Article.objects.get(id=2)
        self.article2 = Article.objects.get(id=3)
        comment1 = Comment.objects.create(content_object=self.article1, text='comment 1')
        comment2 = Comment.objects.create(content_object=self.article2, text='comment 2')

        get_redis_connection().flushdb()
        # Activity 1 and 2 get the same aggregation group.
        self.activity1 = Activity(
            actor=User.objects.get(id=3), verb=CommentVerb, object=comment1,
            target=comment1.content_object, time=datetime.now() - timedelta(minutes=1)
        )
        self.activity2 = Activity(
            actor=User.objects.get(id=3), verb=CommentVerb, object=comment1,
            target=comment1.content_object, time=datetime.now() - timedelta(minutes=2)
        )
        self.activity3 = Activity(
            actor=User.objects.get(id=4), verb=CommentVerb, object=comment2,
            target=comment2.content_object, time=datetime.now()
        )
        feed_manager.add_activity(
            self.activity1,
            [self.user.pk, self.second_user.pk],
            [NotificationFeed]
        )
Beispiel #2
0
 def get_activity(self, membership):
     return Activity(verb=GroupJoinVerb,
                     actor=membership.user,
                     target=membership.abakus_group,
                     object=membership,
                     time=membership.created_at,
                     extra_context={})
Beispiel #3
0
    def handle_interest(self, company_interest):

        activity = Activity(actor=company_interest,
                            verb=CompanyInterestVerb,
                            object=company_interest,
                            time=company_interest.created_at,
                            extra_context={})

        recipients = [
            member.user for member in AbakusGroup.objects.get(
                name="Bedkom").memberships.all()
        ]

        self.manager.add_activity(activity,
                                  [recipient.pk for recipient in recipients],
                                  [NotificationFeed])

        for recipient in recipients:
            notification = CompanyInterestNotification(
                recipient, company_interest=company_interest)
            notification.notify()

        send_email.delay(
            to_email=f'bedriftskontakt@{settings.GSUITE_DOMAIN}',
            context=company_interest.generate_mail_context(),
            subject='En ny bedrift har meldt sin interesse',
            plain_template='companies/email/company_interest.txt',
            html_template='companies/email/company_interest.html',
        )
Beispiel #4
0
 def get_activity(self, registration):
     return Activity(verb=EventRegisterVerb,
                     actor=registration.user,
                     target=registration.event,
                     object=registration,
                     time=registration.created_at,
                     extra_context={})
Beispiel #5
0
 def get_activity(self, comment, reply=False):
     return Activity(actor=comment.created_by,
                     verb=CommentReplyVerb if reply else CommentVerb,
                     object=comment,
                     target=comment.content_object,
                     time=comment.created_at,
                     extra_context={'content': comment.text})
Beispiel #6
0
    def test_create_activity_with_time(self):
        """Check the time storage. The time should be naive."""
        activity = Activity(time=self.test_time,
                            actor=self.user,
                            verb=CommentVerb,
                            object=self.comment,
                            extra_context={'content': self.comment.text})

        self.assertEqual(activity.time, make_naive(self.test_time))
Beispiel #7
0
 def get_activity(self, penalty):
     return Activity(actor=penalty.source_event,
                     verb=PenaltyVerb,
                     object=penalty,
                     target=penalty.user,
                     time=penalty.created_at,
                     extra_context={
                         'reason': penalty.reason,
                         'weight': penalty.weight,
                     })
Beispiel #8
0
    def handle_bump(self, registration):
        activity = Activity(actor=registration.event,
                            verb=RegistrationBumpVerb,
                            object=registration,
                            target=registration.user)
        self.manager.add_activity(activity, [registration.user_id],
                                  [NotificationFeed])

        # Send Notification
        notification = EventBumpNotification(registration.user,
                                             event=registration.event)
        notification.notify()
Beispiel #9
0
    def test_create_activity(self):
        """Check that the objects gets stored as content_strings."""
        activity = Activity(actor=self.user,
                            verb=CommentVerb,
                            object=self.comment,
                            target=self.article,
                            extra_context={'content': self.comment.text})

        self.assertEqual(activity.actor, 'users.user-1')
        self.assertEqual(
            activity.object,
            'comments.comment-{comment_id}'.format(comment_id=self.comment.id))
        self.assertEqual(activity.target, 'articles.article-2')
        self.assertEqual(activity.verb, CommentVerb)
Beispiel #10
0
    def handle_admin_registration(self, registration):
        activity = Activity(actor=registration.event,
                            verb=AdminRegistrationVerb,
                            object=registration,
                            target=registration.user)
        self.manager.add_activity(activity, [registration.user_id],
                                  [NotificationFeed])

        # Send Notification
        notification = EventAdminRegistrationNotification(
            registration.user,
            event=registration.event,
            reason=registration.admin_registration_reason)
        notification.notify()
Beispiel #11
0
    def handle_payment_overdue(self, registration):
        """
        Notify about payment overdue, called from a celery task run by beat.
        """
        activity = Activity(
            actor=registration.event,
            verb=PaymentOverdueVerb,
            object=registration,
            target=registration.user,
        )
        self.manager.add_activity(activity, [registration.user_id],
                                  [NotificationFeed])

        # Send notification
        notification = EventPaymentOverdueNotification(
            registration.user, event=registration.event)
        notification.notify()
Beispiel #12
0
    def handle_send(self, announcement):
        if not announcement.created_by:
            return

        activity = Activity(
            actor=announcement.created_by, verb=AnnouncementVerb, object=announcement,
            time=announcement.created_at, extra_context={}
        )
        recipients = announcement.lookup_recipients()
        self.manager.add_activity(
            activity,
            [recipient.pk for recipient in recipients],
            [NotificationFeed, PersonalFeed]
        )

        # Send notifications
        for recipient in recipients:
            notification = AnnouncementNotification(recipient, announcement=announcement)
            notification.notify()
Beispiel #13
0
    def handle_sent(self, restricted_mail):
        """
        A restricted mail is successfully processed by the system.
        """
        if not restricted_mail.created_by:
            return

        activity = Activity(actor=restricted_mail.created_by,
                            verb=RestrictedMailSent,
                            object=restricted_mail,
                            time=restricted_mail.used,
                            extra_context={})
        self.manager.add_activity(activity, [restricted_mail.created_by.pk],
                                  [NotificationFeed])

        # Send notification
        notification = RestrictedMailSentNotification(
            restricted_mail.created_by)
        notification.notify()
Beispiel #14
0
    def setUp(self):
        self.user = User.objects.get(id=1)
        self.article = Article.objects.get(id=2)
        self.comment = Comment.objects.create(content_object=self.article,
                                              created_by=self.user,
                                              text='comment')

        self.activity = Activity(actor=self.user,
                                 verb=CommentVerb,
                                 object=self.comment,
                                 target=self.article,
                                 extra_context={'content': self.comment.text})
        self.aggregated_activity = AggregatedActivity(
            'test-group', [self.activity],
            created_at=datetime.utcnow(),
            updated_at=datetime.utcnow())

        self.aggregated_serializer = AggregatedActivitySerializer(
            aggregated_activity_class=AggregatedActivity,
            activity_class=Activity,
            model=NotificationFeed.get_timeline_storage().model)
Beispiel #15
0
 def get_activity(self, event):
     return Activity(actor=event.company,
                     verb=EventCreateVerb,
                     object=event,
                     time=event.created_at,
                     extra_context={'title': event.title})
Beispiel #16
0
 def setUp(self):
     self.comment = Comment.objects.first()
     self.activity = Activity(
         actor=self.comment.created_by, verb=CommentVerb, object=self.comment,
         target=self.comment.content_object
     )
Beispiel #17
0
 def get_activity(self, meeting_invitation):
     return Activity(actor=meeting_invitation.created_by,
                     verb=MeetingInvitationVerb,
                     object=meeting_invitation,
                     target=meeting_invitation.user,
                     time=meeting_invitation.created_at)