Esempio n. 1
0
def send_message_notice(user, url, message, label):
    bumps = EyeHistory.objects.filter(Q(url=url) & ~Q(user=user))
    if bumps.count() > 0:
        user_prof = UserProfile.objects.get(user=user)
        sent_user = []
        notice = NoticeType.objects.get(label=label)
        for bump in bumps:
            bump_prof = UserProfile.objects.get(user=bump.user)
            if bump_prof not in sent_user:
                if user_prof in bump_prof.follows.all():
                    Notification.objects.create(recipient=bump.user,
                                                notice_type=notice,
                                                sender=user,
                                                url=url,
                                                message=message)
                    queue(
                        [bump_prof],
                        label,
                        sender=user,
                        extra={
                            'url': url,
                            'message': message,
                            'date': datetime.datetime.now()
                        })
                    sent_user.append(bump_prof)
Esempio n. 2
0
def send_message_notice(user, url, message, label):
    bumps = EyeHistory.objects.filter(Q(url=url) & ~Q(user=user))
    if bumps.count() > 0:
        user_prof = UserProfile.objects.get(user=user)
        sent_user = []
        notice = NoticeType.objects.get(label=label)
        for bump in bumps:
            bump_prof = UserProfile.objects.get(user=bump.user)
            if bump_prof not in sent_user:
                if user_prof in bump_prof.follows.all():
                    Notification.objects.create(recipient=bump.user, notice_type=notice, sender=user, url=url, message=message)
                    queue([bump_prof], label, sender=user, extra={'url': url,
                                                                  'message': message,
                                                                  'date': datetime.datetime.now()})
                    sent_user.append(bump_prof)
Esempio n. 3
0
def check_bumps(user, start_time, end_time, url):
    earlier_time = start_time - datetime.timedelta(minutes=5)
    later_time = end_time + datetime.timedelta(minutes=5)
    bumps = EyeHistory.objects.filter(Q(url=url) & ~Q(user_id=user.id) & (Q(end_time__gte=earlier_time) & Q(start_time__lte=later_time)))
    if bumps.count() > 0:
        user_prof = UserProfile.objects.get(user=user)
        n = NoticeType.objects.get(label="bump_follower")
        sent_user = []
        for bump in bumps:
            bump_prof = UserProfile.objects.get(user=bump.user)
            if user_prof not in sent_user:
                if bump_prof in user_prof.follows.all():
                    Notification.objects.create(recipient=user, notice_type=n, sender=bump.user, url=url)
                    queue([user], "bump_follower", sender=bump.user, extra={'url': url, 'date': datetime.datetime.now()})
                    sent_user.append(user_prof)
            if bump_prof not in sent_user:
                if user_prof in bump_prof.follows.all():
                    Notification.objects.create(recipient=bump.user, notice_type=n, sender=user, url=url)
                    queue([bump.user], "bump_follower", sender=user, extra={'url': url, 'date': datetime.datetime.now()})
                    sent_user.append(bump_prof)
Esempio n. 4
0
def check_bumps(user, start_time, end_time, url):
    earlier_time = start_time - datetime.timedelta(minutes=5)
    later_time = end_time + datetime.timedelta(minutes=5)
    bumps = EyeHistory.objects.filter(Q(url=url) & ~Q(user_id=user.id) & (Q(end_time__gte=earlier_time) & Q(start_time__lte=later_time)))
    if bumps.count() > 0:
        user_prof = UserProfile.objects.get(user=user)
        n = NoticeType.objects.get(label="bump_follower")
        sent_user = []
        for bump in bumps:
            bump_prof = UserProfile.objects.get(user=bump.user)
            if user_prof not in sent_user:
                if bump_prof in user_prof.follows.all():
                    Notification.objects.create(recipient=user, notice_type=n, sender=bump.user, url=url)
                    queue([user], "bump_follower", sender=bump.user, extra={'url': url, 'date': datetime.datetime.now()})
                    sent_user.append(user_prof)
            if bump_prof not in sent_user:
                if user_prof in bump_prof.follows.all():
                    Notification.objects.create(recipient=bump.user, notice_type=n, sender=user, url=url)
                    queue([bump.user], "bump_follower", sender=user, extra={'url': url, 'date': datetime.datetime.now()})
                    sent_user.append(bump_prof)
 def test_emit_notices(self):
     users = [self.user, self.user2]
     queue(users, "label")
     queue(users, "label", send_at=timezone.now())
     queue(users, "label", send_at=(timezone.now() + timezone.timedelta(minutes=10)))
     management.call_command("emit_notices")
     self.assertEqual(len(mail.outbox), 4)
     self.assertIn(self.user.email, mail.outbox[0].to)
     self.assertIn(self.user2.email, mail.outbox[1].to)
     self.assertEqual(len(NoticeQueueBatch.objects.all()), 1)
Esempio n. 6
0
 def test_queue_queryset(self):
     users = get_user_model().objects.all()
     queue(users, "label")
     self.assertEqual(len(mail.outbox), 0)
     self.assertEqual(NoticeQueueBatch.objects.count(), 1)