Exemplo n.º 1
0
def guests_residents_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')
    departing_today = Reservation.objects.filter(location=location).filter(
        depart=today).filter(status='confirmed')
    events_today = published_events_today_local(location=location)

    if not arriving_today and not departing_today and not events_today:
        logger.debug("Nothing happening today at %s, skipping daily email" %
                     location.name)
        return

    subject = "[%s] Events, Arrivals and Departures for %s" % (
        location.email_subject_prefix, str(today.date()))

    admin_emails = []
    for admin in location.house_admins.all():
        if not admin.email in admin_emails:
            admin_emails.append(admin.email)

    print admin_emails

    to_emails = []
    for r in Reservation.objects.confirmed_on_date(today, location):
        if (not r.user.email in admin_emails) and (not r.user.email
                                                   in to_emails):
            to_emails.append(r.user.email)

    # Add all the non-admin residents at this location (admins get a different
    # email)
    for r in location.residents.all():
        if (not r.email in admin_emails) and (not r.email in to_emails):
            to_emails.append(r.email)

    if len(to_emails) == 0:
        return None

    c = Context({
        'today': today,
        'domain': Site.objects.get_current().domain,
        'location': location,
        'arriving': arriving_today,
        'departing': departing_today,
        'events_today': events_today,
    })
    text_content, html_content = render_templates(
        c, location, LocationEmailTemplate.GUEST_DAILY)

    mailgun_data = {
        "from": location.from_email(),
        "to": to_emails,
        "subject": subject,
        "text": text_content,
    }
    if html_content:
        mailgun_data["html"] = html_content

    return mailgun_send(mailgun_data)
Exemplo n.º 2
0
def guests_residents_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')
	departing_today = Reservation.objects.filter(location=location).filter(depart=today).filter(status='confirmed')
	events_today = published_events_today_local(location=location)

	if not arriving_today and not departing_today and not events_today:
		logger.debug("Nothing happening today at %s, skipping daily email" % location.name)
		return

	subject = "[%s] Events, Arrivals and Departures for %s" % (location.email_subject_prefix, str(today.date()))
	
	admin_emails = []
	for admin in location.house_admins.all():
		if not admin.email in admin_emails:
			admin_emails.append(admin.email)
	
	print admin_emails

	to_emails = []
	for r in Reservation.objects.confirmed_on_date(today, location):
		if (not r.user.email in admin_emails) and (not r.user.email in to_emails):
			to_emails.append(r.user.email)

	# Add all the non-admin residents at this location (admins get a different
	# email)
	for r in location.residents.all():
		if (not r.email in admin_emails) and (not r.email in to_emails):
			to_emails.append(r.email)
	
	print "people receiving the non-admin daily update"
	print to_emails

	if len(to_emails) == 0:
		return None
	
	c = Context({
		'today': today,
		'domain': Site.objects.get_current().domain,
		'location': location,
		'arriving' : arriving_today,
		'departing' : departing_today,
		'events_today': events_today,
	})
	text_content, html_content = render_templates(c, location, LocationEmailTemplate.GUEST_DAILY)

	mailgun_data={
		"from": location.from_email(),
		"to": to_emails,
		"subject": subject,
		"text": text_content,
	}
	if html_content:
		mailgun_data["html"] = html_content

	return mailgun_send(mailgun_data)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def today(request, location_slug):
	location = get_location(location_slug)
	# get all the reservations that intersect today (including those departing
	# and arriving today)
	today = timezone.now()
	reservations_today = Reservation.objects.filter(Q(status="confirmed") | Q(status="approved")).exclude(depart__lt=today).exclude(arrive__gt=today)
	guests_today = []
	for r in reservations_today:
		guests_today.append(r.user)
	residents = location.residents.all()
	people_today = guests_today + list(residents)

	events_today = published_events_today_local(location)
	return render(request, "today.html", {'people_today': people_today, 'events_today': events_today})
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def guest_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')
    departing_today = Reservation.objects.filter(location=location).filter(
        depart=today).filter(status='confirmed')
    events_today = published_events_today_local(location=location)

    if not arriving_today and not departing_today and not events_today:
        logger.debug("Nothing happening today at %s, skipping daily email" %
                     location.name)
        return

    plaintext = get_template('emails/guest_daily_update.txt')
    c = Context({
        'today': today,
        'domain': Site.objects.get_current().domain,
        'location': location,
        'arriving': arriving_today,
        'departing': departing_today,
        'events_today': events_today,
    })
    text_content = plaintext.render(c)
    subject = "[%s] Events, Arrivals and Departures for %s" % (
        location.email_subject_prefix, str(today.date()))

    guest_emails = []
    for r in Reservation.today.confirmed(location):
        if not r.user.email in guest_emails:
            guest_emails.append(r.user.email)
    if len(guest_emails) == 0:
        return None

    mailgun_data = {
        "from": location.from_email(),
        "to": guest_emails,
        "subject": subject,
        "text": text_content,
    }
    return mailgun_send(mailgun_data)
Exemplo n.º 8
0
def guest_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')
	departing_today = Reservation.objects.filter(location=location).filter(depart=today).filter(status='confirmed')
	events_today = published_events_today_local(location=location)

	if not arriving_today and not departing_today and not events_today:
		logger.debug("Nothing happening today at %s, skipping daily email" % location.name)
		return

	plaintext = get_template('emails/guest_daily_update.txt')
	c = Context({
		'today': today,
		'domain': Site.objects.get_current().domain,
		'location': location,		
		'arriving' : arriving_today,
		'departing' : departing_today,
		'events_today': events_today,
	})
	text_content = plaintext.render(c)
	subject = "[%s] Events, Arrivals and Departures for %s" % (location.email_subject_prefix, str(today.date()))
	
	guest_emails = []
	for r in Reservation.today.confirmed(location):
		if not r.user.email in guest_emails:
			guest_emails.append(r.user.email)
	if len(guest_emails) == 0:
		return None
	
	mailgun_data={
		"from": location.from_email(),
		"to": guest_emails,
		"subject": subject,
		"text": text_content,
	}
	return mailgun_send(mailgun_data)
Exemplo n.º 9
0
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)