Send emails to team admins when they get new members, and to event hosts when they get new attendees

This commit is contained in:
Michael Hall 2018-05-13 16:59:03 -04:00
parent 2f6b563841
commit 89d691b6ba
9 changed files with 174 additions and 2 deletions

View file

@ -123,8 +123,8 @@ class MemberAdmin(admin.ModelAdmin):
admin.site.register(Member, MemberAdmin)
class AttendeeAdmin(admin.ModelAdmin):
list_display = ('__str__', 'role', 'status', 'last_reminded')
list_filter = ('role', 'status')
list_display = ('__str__', 'role', 'status', 'joined_date', 'last_reminded')
list_filter = ('role', 'status', 'joined_date')
admin.site.register(Attendee, AttendeeAdmin)
class CategoryAdmin(admin.ModelAdmin):

View file

@ -0,0 +1,59 @@
from django.core.management.base import BaseCommand, CommandError
from django.urls import reverse
from django.core.mail import send_mail
from django.template.loader import get_template, render_to_string
from django.conf import settings
from django.contrib.sites.models import Site
from django.utils import timezone
from events.models import Event, Attendee
import datetime
class Command(BaseCommand):
help = "Sends email to event hosts about new attendees"
def handle(self, *args, **options):
# Attendees who recently joined
attendees = Attendee.objects.filter(role=Attendee.NORMAL, joined_date__gte=timezone.now() - datetime.timedelta(days=1)).order_by('event')
current_event = None
new_attendees = []
for attendee in attendees:
if attendee.event != current_event:
send_new_attendees(current_event, new_attendees)
current_event = attendee.event
new_attendees = []
new_attendees.append(attendee)
if current_event is not None:
send_new_attendees(current_event, new_attendees)
def send_new_attendees(event, new_attendees):
if len(new_attendees) < 1:
return
host_emails = [attendee.user.user.email for attendee in Attendee.objects.filter(event=event, role=Attendee.HOST) if attendee.user.user.account.is_email_confirmed]
if len(host_emails) < 1:
return
context = {
'event': event,
'attendees': new_attendees,
'site': Site.objects.get(id=1)
}
email_subject = '[GetTogether] New event attendees'
email_body_text = render_to_string('get_together/emails/new_event_attendees.txt', context)
email_body_html = render_to_string('get_together/emails/new_event_attendees.html', context)
email_recipients = host_emails
email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community')
send_mail(
from_email=email_from,
html_message=email_body_html,
message=email_body_text,
recipient_list=email_recipients,
subject=email_subject,
)

View file

@ -0,0 +1,59 @@
from django.core.management.base import BaseCommand, CommandError
from django.urls import reverse
from django.core.mail import send_mail
from django.template.loader import get_template, render_to_string
from django.conf import settings
from django.contrib.sites.models import Site
from django.utils import timezone
from events.models import Event, Member
import datetime
class Command(BaseCommand):
help = "Sends email to team admins about new members"
def handle(self, *args, **options):
# members who recently joined
members = Member.objects.filter(role=Member.NORMAL, joined_date__gte=timezone.now() - datetime.timedelta(days=1)).order_by('team')
current_team = None
new_members = []
for member in members:
if member.team != current_team:
send_new_members(current_team, new_members)
current_team = member.team
new_members = []
new_members.append(member)
if current_team is not None:
send_new_members(current_team, new_members)
def send_new_members(team, new_members):
if len(new_members) < 1:
return
admin_emails = [member.user.user.email for member in Member.objects.filter(team=team, role=Member.ADMIN) if member.user.user.account.is_email_confirmed]
if len(admin_emails) < 1:
return
context = {
'team': team,
'members': new_members,
'site': Site.objects.get(id=1)
}
email_subject = '[GetTogether] New team members'
email_body_text = render_to_string('get_together/emails/new_team_members.txt', context)
email_body_html = render_to_string('get_together/emails/new_team_members.html', context)
email_recipients = admin_emails
email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community')
send_mail(
from_email=email_from,
html_message=email_body_html,
message=email_body_text,
recipient_list=email_recipients,
subject=email_subject,
)

View file

@ -1,3 +1,6 @@
= Email from GetTogether.Community =
{% block content %}{% endblock %}
--
This is an automated email sent by https://gettogether.community
Learn more at https://github.com/GetTogetherComm/GetTogether/

View file

@ -0,0 +1,14 @@
{% extends "get_together/emails/base.html" %}
{% block content %}
<h3>You have new attendees for <b>{{event.name|striptags}}</b></h3>
<ul>
{% for attendee in attendees %}
<li><a href="https://{{site.domain}}{% url 'show-profile' attendee.user.id %}">{{attendee.user}}</a> - {{attendee.status_name}}</li>
{% endfor %}
</ul>
<br>
<a href="{{event.get_full_url}}" title="{{ event.name|striptags }} page.">View this event.</a>
</p>
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends 'get_together/emails/base.txt' %}
{% block content %}
== You have new attendees for {{event.name|striptags}} ==
{% for attendee in attendees %}
* {{attendee.user}} - {{attendee.status_name}}
{% endfor %}
Click here to view this event: {{event.get_full_url}}
{% endblock %}

View file

@ -0,0 +1,14 @@
{% extends "get_together/emails/base.html" %}
{% block content %}
<h3>You have members of <b>{{team.name|striptags}}</b></h3>
<ul>
{% for member in members %}
<li><a href="https://{{site.domain}}{% url 'show-profile' member.user.id %}">{{member.user}}</a></li>
{% endfor %}
</ul>
<br>
<a href="https://{{site.domain}}{% url 'show-team' team.id %}" title="{{ team.name|striptags }} page.">View this team.</a>
</p>
{% endblock %}

View file

@ -0,0 +1,11 @@
{% extends 'get_together/emails/base.txt' %}
{% block content %}
== You have new members of {{team.name|striptags}} ==
{% for member in members %}
* {{member.user}}
{% endfor %}
Click here to view this team: https://{{site.domain}}{% url 'show-team' team.id %}
{% endblock %}

View file

@ -243,6 +243,7 @@ def attend_event(request, event_id):
attendee.status = Attendee.MAYBE
if request.GET.get('response', None) == 'no':
attendee.status = Attendee.NO
attendee.joined_date = timezone.now()
attendee.save()
if attendee.status == Attendee.YES:
messages.add_message(request, messages.SUCCESS, message=_("We'll see you there!"))