def admin_daily_update(location): # this is split out by location because each location has a timezone that affects the value of 'today' today = timezone.localtime(timezone.now()) arriving_today = Reservation.objects.filter(location=location).filter( arrive=today).filter(status='confirmed') maybe_arriving_today = Reservation.objects.filter( location=location).filter(arrive=today).filter(status='approved') pending_now = Reservation.objects.filter(location=location).filter( status='pending') approved_now = Reservation.objects.filter(location=location).filter( status='approved') departing_today = Reservation.objects.filter(location=location).filter( depart=today).filter(status='confirmed') events_today = published_events_today_local(location=location) pending_or_feedback = events_pending(location=location) if not arriving_today and not departing_today and not events_today and not maybe_arriving_today and not pending_now and not approved_now: logger.debug("Nothing happening today at %s, skipping daily email" % location.name) return subject = "[%s] %s Events and Guests" % (location.email_subject_prefix, str(today.date())) admins_emails = [] for admin in location.house_admins.all(): if not admin.email in admins_emails: admins_emails.append(admin.email) if len(admins_emails) == 0: return None c = Context({ 'today': today, 'domain': Site.objects.get_current().domain, 'location': location, 'arriving': arriving_today, 'maybe_arriving': maybe_arriving_today, 'pending_now': pending_now, 'approved_now': approved_now, 'departing': departing_today, 'events_today': events_today, 'events_pending': pending_or_feedback['pending'], 'events_feedback': pending_or_feedback['feedback'], }) text_content, html_content = render_templates( c, location, LocationEmailTemplate.ADMIN_DAILY) mailgun_data = { "from": location.from_email(), "to": admins_emails, "subject": subject, "text": text_content, } if html_content: mailgun_data["html"] = html_content return mailgun_send(mailgun_data)
def admin_daily_update(location): # this is split out by location because each location has a timezone that affects the value of 'today' today = timezone.localtime(timezone.now()).date() arriving_today = Use.objects.filter(location=location).filter(arrive=today).filter(status='confirmed') maybe_arriving_today = Use.objects.filter(location=location).filter(arrive=today).filter(status='approved') pending_now = Use.objects.filter(location=location).filter(status='pending') approved_now = Use.objects.filter(location=location).filter(status='approved') departing_today = Use.objects.filter(location=location).filter(depart=today).filter(status='confirmed') events_today = published_events_today_local(location=location) pending_or_feedback = events_pending(location=location) # if there are subscriptions ready for billing, the bills should have been # generated by another task. this is for notification purposes only so the # admins know the check 'em out. subscriptions_ready = Subscription.objects.ready_for_billing(location, target_date=today) if not arriving_today and not departing_today and not events_today and not maybe_arriving_today and not pending_now and not approved_now and not subscriptions_ready: logger.debug("Nothing happening today at %s, skipping daily email" % location.name) return subject = "[%s] %s Events and Guests" % (location.email_subject_prefix, today) admins_emails = [] for admin in location.house_admins.all(): if not admin.email in admins_emails: admins_emails.append(admin.email) if len(admins_emails) == 0: logger.debug('%s: No admins to send to' % location.slug) return None c = Context({ 'today': today, 'domain': Site.objects.get_current().domain, 'location': location, 'arriving' : arriving_today, 'maybe_arriving' : maybe_arriving_today, 'pending_now' : pending_now, 'approved_now' : approved_now, 'departing' : departing_today, 'events_today': events_today, 'events_pending': pending_or_feedback['pending'], 'events_feedback': pending_or_feedback['feedback'], 'subscriptions_ready': subscriptions_ready, }) text_content, html_content = render_templates(c, location, LocationEmailTemplate.ADMIN_DAILY) mailgun_data={ "from": location.from_email(), "to": admins_emails, "subject": subject, "text": text_content, } if html_content: mailgun_data["html"] = html_content return mailgun_send(mailgun_data)
def admin_daily_update(location): # this is split out by location because each location has a timezone that affects the value of 'today' today = timezone.localtime(timezone.now()) arriving_today = Reservation.objects.filter(location=location).filter(arrive=today).filter(status='confirmed') maybe_arriving_today = Reservation.objects.filter(location=location).filter(arrive=today).filter(status='approved') pending_now = Reservation.objects.filter(location=location).filter(status='pending') approved_now = Reservation.objects.filter(location=location).filter(status='approved') departing_today = Reservation.objects.filter(location=location).filter(depart=today).filter(status='confirmed') events_today = published_events_today_local(location=location) pending_or_feedback = events_pending(location=location) if not arriving_today and not departing_today and not events_today and not maybe_arriving_today and not pending_now and not approved_now: logger.debug("Nothing happening today at %s, skipping daily email" % location.name) return subject = "[%s] %s Events and Guests" % (location.email_subject_prefix, str(today.date())) admins_emails = [] for admin in location.house_admins.all(): if not admin.email in admins_emails: admins_emails.append(admin.email) if len(admins_emails) == 0: return None c = Context({ 'today': today, 'domain': Site.objects.get_current().domain, 'location': location, 'arriving' : arriving_today, 'maybe_arriving' : maybe_arriving_today, 'pending_now' : pending_now, 'approved_now' : approved_now, 'departing' : departing_today, 'events_today': events_today, 'events_pending': pending_or_feedback['pending'], 'events_feedback': pending_or_feedback['feedback'], }) text_content, html_content = render_templates(c, location, LocationEmailTemplate.ADMIN_DAILY) mailgun_data={ "from": location.from_email(), "to": admins_emails, "subject": subject, "text": text_content, } if html_content: mailgun_data["html"] = html_content return mailgun_send(mailgun_data)
def admin_daily_update(location): # this is split out by location because each location has a timezone that affects the value of 'today' today = timezone.localtime(timezone.now()).date() arriving_today = Use.objects.filter(location=location).filter( arrive=today).filter(status='confirmed') maybe_arriving_today = Use.objects.filter(location=location).filter( arrive=today).filter(status='approved') pending_now = Use.objects.filter(location=location).filter( status='pending') approved_now = Use.objects.filter(location=location).filter( status='approved') departing_today = Use.objects.filter(location=location).filter( depart=today).filter(status='confirmed') events_today = published_events_today_local(location=location) pending_or_feedback = events_pending(location=location) # if there are subscriptions ready for billing, the bills should have been # generated by another task. this is for notification purposes only so the # admins know the check 'em out. subscriptions_ready = Subscription.objects.ready_for_billing( location, target_date=today) if not arriving_today and not departing_today and not events_today and not maybe_arriving_today and not pending_now and not approved_now and not subscriptions_ready: logger.debug("Nothing happening today at %s, skipping daily email" % location.name) return subject = "[%s] %s Events and Guests" % (location.email_subject_prefix, today) admins_emails = [] for admin in location.house_admins.all(): if not admin.email in admins_emails: admins_emails.append(admin.email) if len(admins_emails) == 0: logger.debug('%s: No admins to send to' % location.slug) return None c = { 'today': today, 'domain': Site.objects.get_current().domain, 'location': location, 'arriving': arriving_today, 'maybe_arriving': maybe_arriving_today, 'pending_now': pending_now, 'approved_now': approved_now, 'departing': departing_today, 'events_today': events_today, 'events_pending': pending_or_feedback['pending'], 'events_feedback': pending_or_feedback['feedback'], 'subscriptions_ready': subscriptions_ready, } text_content, html_content = render_templates( c, location, LocationEmailTemplate.ADMIN_DAILY) mailgun_data = { "from": location.from_email(), "to": admins_emails, "subject": subject, "text": text_content, } if html_content: mailgun_data["html"] = html_content return mailgun_send(mailgun_data)