diff --git a/events/admin.py b/events/admin.py index 60224a1..d01770b 100644 --- a/events/admin.py +++ b/events/admin.py @@ -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): diff --git a/get_together/management/commands/send_daily_attendee_update.py b/get_together/management/commands/send_daily_attendee_update.py new file mode 100644 index 0000000..9b5d0bc --- /dev/null +++ b/get_together/management/commands/send_daily_attendee_update.py @@ -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, + ) diff --git a/get_together/management/commands/send_daily_member_update.py b/get_together/management/commands/send_daily_member_update.py new file mode 100644 index 0000000..07c75b2 --- /dev/null +++ b/get_together/management/commands/send_daily_member_update.py @@ -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, + ) diff --git a/get_together/templates/get_together/emails/base.txt b/get_together/templates/get_together/emails/base.txt index f6f6f91..beeb450 100644 --- a/get_together/templates/get_together/emails/base.txt +++ b/get_together/templates/get_together/emails/base.txt @@ -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/ diff --git a/get_together/templates/get_together/emails/new_event_attendees.html b/get_together/templates/get_together/emails/new_event_attendees.html new file mode 100644 index 0000000..3abe7ec --- /dev/null +++ b/get_together/templates/get_together/emails/new_event_attendees.html @@ -0,0 +1,14 @@ +{% extends "get_together/emails/base.html" %} + +{% block content %} +