Example #1
0
 def send_to_me(self, request, queryset):
     if not request.user.email:
         raise ValueError("No e-mail address for {} when trying to send a sample detention e-mail.".format(request.user))
     
     for detention in queryset:
         try:
             message = get_message(detention, override_recipients=[request.user.email])
         except ValueError as e:
             send_mail("Error sending detention", str(e), '*****@*****.**', [request.user.email])
             continue
             
         message.send()
 def handle(self, *args, **kwargs):
     logger.info("Beginning detention send routine")
             
     detention_mailer = DetentionMailer.objects.get()
     
     unsent_detentions = Detention.objects.filter(sent=False)
     
     if detention_mailer.do_not_send_same_day_before:
         # Convert the surpression time into a fully aware datetime object
         # so that we can compare it to the current time, and, if needed,
         # exclude detentions that were assigned today
         today = date.today()
         surpress_time = detention_mailer.do_not_send_same_day_before
         nonaware_surpress_check = datetime(today.year, today.month, today.day, surpress_time.hour, surpress_time.minute)
         surpress_check = timezone.get_current_timezone().localize(nonaware_surpress_check)
         
         # It has not yet hit the time required to send today's detentions
         if timezone.now() < surpress_check:
             # Only include detentions *before* today
             unsent_detentions = unsent_detentions.filter(detention_date__lt=date.today())
     
     error_recipients = [o.address for o in DetentionErrorNotification.objects.filter(mailer=detention_mailer)]
     
     for detention in unsent_detentions:
         try:
             message = get_message(detention)
             message.send()
             
             #Sleep for 1 second for SES rate limiting
             #time.sleep(1)
             
             detention.sent = True
             detention.save()
             
         except ValueError as e:
             send_mail("Error sending detention", str(e), '*****@*****.**', error_recipients)
             continue