def testAutoMail(self):
        models.Prize.objects.update(state='ACCEPTED')
        prizes = models.Prize.objects.all()
        donors = models.Donor.objects.all()
        winningDonors = {}

        for donor in donors:
            winningDonors[donor] = []

        for prize in prizes:
            if self.rand.getrandbits(1) == 0:
                prizeWinner = models.PrizeWinner.objects.create(
                    winner=self.rand.choice(donors),
                    prize=prize,
                    acceptcount=1,
                    pendingcount=0,
                    emailsent=True,
                    acceptemailsentcount=1,
                    shippingstate='SHIPPED',
                    shippingemailsent=False,
                )
                if prize.key_code:
                    key = models.PrizeKey.objects.get(prize=prize)
                    key.prize_winner = prizeWinner
                    key.save()
                winningDonors[prizeWinner.winner].append(prizeWinner)

        winnerList = sum(winningDonors.values(), [])
        self.assertSetEqual(
            set(prizemail.prizes_with_shipping_email_pending(self.event)),
            set(winnerList),
        )

        prizemail.automail_shipping_email_notifications(
            self.event, winnerList, self.templateEmail, sender=self.sender
        )

        for winner in winningDonors:
            prizeWinners = winningDonors[winner]
            winnerMail = post_office.models.Email.objects.filter(to=winner.email)

            if len(prizeWinners) == 0:
                self.assertEqual(0, winnerMail.count())
            else:
                self.assertEqual(1, winnerMail.count())
                eventId, winnerId, mailedPrizeWinnerIds, keys, reply = self._parseMail(
                    winnerMail[0]
                )
                self.assertEqual(self.event.id, eventId)
                self.assertEqual(winner.id, winnerId)
                self.assertEqual(len(mailedPrizeWinnerIds), len(prizeWinners))
                for prizeWinner in prizeWinners:
                    self.assertIn(prizeWinner.id, mailedPrizeWinnerIds)
                    self.assertTrue(prizeWinner.shippingemailsent)
                    if prizeWinner.prize.key_code:
                        self.assertIn(prizeWinner.prizekey.key, keys)
                self.assertEqual(self.sender, reply)
 def handle(self, *args, **options):
     event = viewutil.get_event(options['event'])
     prizeWinners = prizemail.prizes_with_shipping_email_pending(event)
     emailTemplate = options['template'] or event.prizeshippedemailtemplate
     
     if emailTemplate == None:
         print("No default prize shipped email template specified on event {0}, cannot send e-mails.".format(event.short))
     else:
         prizemail.automail_shipping_email_notifications(event, prizeWinners, emailTemplate)
    def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)

        event = options['event']
        prizeWinners = prizemail.prizes_with_shipping_email_pending(event)
        emailTemplate = options['template'] or event.prizeshippedemailtemplate
        dryRun = options['dry_run']
        
        if emailTemplate == None:
            self.message("No default prize shipped email template specified on event {0}, cannot send e-mails.".format(event.short))
        else:
            prizemail.automail_shipping_email_notifications(event, prizeWinners, emailTemplate, verbosity=self.verbosity, dry_run=dryRun)
Exemplo n.º 4
0
    def automail_prize_shipping_notifications(request, event=None):
        if not hasattr(settings, 'EMAIL_HOST'):
            return HttpResponse('Email not enabled on this server.')

        event = viewutil.get_event(event)

        if not event.id:
            return render(
                request,
                'tracker/eventlist.html',
                {
                    'events': models.Event.objects.all(),
                    'pattern': 'admin:automail_prize_shipping_notifications',
                    'subheading': 'Mail Prize Shipping Notifications',
                },
            )

        prizewinners = prizemail.prizes_with_shipping_email_pending(event)
        if request.method == 'POST':
            form = forms.AutomailPrizeShippingNotifyForm(
                prizewinners=prizewinners, data=request.POST)
            if form.is_valid():
                prizemail.automail_shipping_email_notifications(
                    event,
                    form.cleaned_data['prizewinners'],
                    form.cleaned_data['emailtemplate'],
                    sender=form.cleaned_data['fromaddress'],
                    replyTo=form.cleaned_data['replyaddress'],
                )
                viewutil.tracker_log(
                    'prize',
                    'Mailed prize shipping notifications',
                    event=event,
                    user=request.user,
                )
                return render(
                    request,
                    'admin/tracker/automail_prize_winners_shipping_notifications_post.html',
                    {'prizewinners': form.cleaned_data['prizewinners']},
                )
        else:
            form = forms.AutomailPrizeShippingNotifyForm(
                prizewinners=prizewinners)
        return render(
            request,
            'admin/tracker/automail_prize_winners_shipping_notifications.html',
            {'form': form},
        )
Exemplo n.º 5
0
def automail_prize_shipping_notifications(request):
  if not hasattr(settings, 'EMAIL_HOST'):
    return HttpResponse("Email not enabled on this server.")
  currentEvent = viewutil.get_selected_event(request)
  if currentEvent == None:
    return HttpResponse("Please select an event first")
  prizewinners = prizemail.prizes_with_shipping_email_pending(currentEvent)
  if request.method == 'POST':
    form = forms.AutomailPrizeShippingNotifyForm(prizewinners=prizewinners, data=request.POST)
    if form.is_valid():
      prizemail.automail_shipping_email_notifications(currentEvent, form.cleaned_data['prizewinners'], form.cleaned_data['emailtemplate'], sender=form.cleaned_data['fromaddress'], replyTo=form.cleaned_data['replyaddress'])
      viewutil.tracker_log(u'prize', u'Mailed prize shipping notifications', event=currentEvent, user=request.user)
      return render(request, 'admin/automail_prize_winners_shipping_notifications_post.html', { 'prizewinners': form.cleaned_data['prizewinners'] })
  else:
    form = forms.AutomailPrizeShippingNotifyForm(prizewinners=prizewinners)
  return render(request, 'admin/automail_prize_winners_shipping_notifications.html', { 'form': form })
    def testAutomail(self):
        models.Prize.objects.update(state='ACCEPTED')
        prizes = models.Prize.objects.all()
        donors = models.Donor.objects.all()
        winningDonors = {}

        for donor in donors:
            winningDonors[donor] = []

        for prize in prizes:
            if self.rand.getrandbits(1) == 0:
                prizeWinner = models.PrizeWinner.objects.create(
                    winner=self.rand.choice(donors), prize=prize, acceptcount=1, pendingcount=0, emailsent=True, acceptemailsentcount=1, shippingstate='SHIPPED', shippingemailsent=False)
                winningDonors[prizeWinner.winner].append(prizeWinner)

        winnerList = reduce(lambda x, y: x + y, winningDonors.values(), [])
        self.assertItemsEqual(
            prizemail.prizes_with_shipping_email_pending(self.event), winnerList)

        prizemail.automail_shipping_email_notifications(
            self.event, winnerList, self.templateEmail, sender=self.sender)

        for winner in winningDonors:
            prizeWinners = winningDonors[winner]
            winnerMail = post_office.models.Email.objects.filter(
                to=winner.email)

            if len(prizeWinners) == 0:
                self.assertEqual(0, winnerMail.count())
            else:
                self.assertEqual(1, winnerMail.count())
                eventId, winnerId, mailedPrizeWinnerIds, reply = self._parseMail(
                    winnerMail[0])
                self.assertEqual(self.event.id, eventId)
                self.assertEqual(winner.id, winnerId)
                self.assertEqual(len(mailedPrizeWinnerIds), len(prizeWinners))
                for prizeWinner in prizeWinners:
                    self.assertTrue(prizeWinner.id in mailedPrizeWinnerIds)
                    self.assertTrue(prizeWinner.shippingemailsent)
                self.assertEqual(self.sender, reply)
Exemplo n.º 7
0
 def automail_prize_shipping_notifications(request):
     if not hasattr(settings, 'EMAIL_HOST'):
         return HttpResponse('Email not enabled on this server.')
     currentEvent = viewutil.get_selected_event(request)
     if currentEvent is None:
         return HttpResponse('Please select an event first')
     prizewinners = prizemail.prizes_with_shipping_email_pending(
         currentEvent)
     if request.method == 'POST':
         form = forms.AutomailPrizeShippingNotifyForm(
             prizewinners=prizewinners, data=request.POST)
         if form.is_valid():
             prizemail.automail_shipping_email_notifications(
                 currentEvent,
                 form.cleaned_data['prizewinners'],
                 form.cleaned_data['emailtemplate'],
                 sender=form.cleaned_data['fromaddress'],
                 replyTo=form.cleaned_data['replyaddress'],
             )
             viewutil.tracker_log(
                 'prize',
                 'Mailed prize shipping notifications',
                 event=currentEvent,
                 user=request.user,
             )
             return render(
                 request,
                 'admin/automail_prize_winners_shipping_notifications_post.html',
                 {'prizewinners': form.cleaned_data['prizewinners']},
             )
     else:
         form = forms.AutomailPrizeShippingNotifyForm(
             prizewinners=prizewinners)
     return render(
         request,
         'admin/automail_prize_winners_shipping_notifications.html',
         {'form': form},
     )