diff --git a/src/shop/email.py b/src/shop/email.py index de18e082..9be19f58 100644 --- a/src/shop/email.py +++ b/src/shop/email.py @@ -15,7 +15,7 @@ def send_creditnote_email(creditnote): return add_outgoing_email( text_template='emails/creditnote_email.txt', html_template='emails/creditnote_email.html', - recipients=creditnote.user.email, + to_recipients=creditnote.user.email, formatdict=formatdict, subject=subject, attachment=creditnote.pdf.read(), @@ -37,7 +37,7 @@ def send_invoice_email(invoice): return add_outgoing_email( text_template='emails/invoice_email.txt', html_template='emails/invoice_email.html', - recipients=invoice.order.user.email, + to_recipients=invoice.order.user.email, formatdict=formatdict, subject=subject, attachment=invoice.pdf.read(), @@ -48,6 +48,6 @@ def send_invoice_email(invoice): def send_test_email(recipient): return add_outgoing_email( text_template='emails/testmail.txt', - recipients=recipient, + to_recipients=recipient, subject='testmail from bornhack website' ) diff --git a/src/teams/admin.py b/src/teams/admin.py index cc440820..2eb6d5dd 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin from .models import Team, TeamArea, TeamMember -from .email import send_add_membership_email, send_remove_membership_email +from .email import add_added_membership_email, add_removed_membership_email admin.site.register(TeamArea) @@ -41,7 +41,7 @@ class TeamMemberAdmin(admin.ModelAdmin): membership.approved = True membership.save() updated += 1 - send_add_membership_email(membership) + add_added_membership_email(membership) self.message_user( request, @@ -57,7 +57,7 @@ class TeamMemberAdmin(admin.ModelAdmin): updated = 0 for membership in queryset: - send_remove_membership_email(membership) + add_removed_membership_email(membership) membership.delete() updated += 1 @@ -69,4 +69,3 @@ class TeamMemberAdmin(admin.ModelAdmin): ) ) remove_member.description = 'Remove a user from the team.' - diff --git a/src/teams/email.py b/src/teams/email.py index 8917241b..62d997db 100644 --- a/src/teams/email.py +++ b/src/teams/email.py @@ -3,7 +3,7 @@ import logging logger = logging.getLogger("bornhack.%s" % __name__) -def send_add_membership_email(membership): +def add_added_membership_email(membership): formatdict = { 'team': membership.team.name, 'camp': membership.team.camp.title @@ -12,13 +12,13 @@ def send_add_membership_email(membership): return add_outgoing_email( text_template='emails/add_membership_email.txt', html_template='emails/add_membership_email.html', - recipient=membership.user.email, + to_recipients=membership.user.email, formatdict=formatdict, subject='Team update from {}'.format(membership.team.camp.title) ) -def send_remove_membership_email(membership): +def add_removed_membership_email(membership): formatdict = { 'team': membership.team.name, 'camp': membership.team.camp.title @@ -34,13 +34,13 @@ def send_remove_membership_email(membership): return add_outgoing_email( text_template=text_template, html_template=html_template, - recipient=membership.user.email, + to_recipients=membership.user.email, formatdict=formatdict, subject='Team update from {}'.format(membership.team.camp.title) ) -def send_new_membership_email(membership): +def add_new_membership_email(membership): formatdict = { 'team': membership.team.name, 'camp': membership.team.camp.title @@ -49,7 +49,7 @@ def send_new_membership_email(membership): return add_outgoing_email( text_template='emails/new_membership_email.txt', html_template='emails/new_membership_email.html', - recipients=membership.team.responsible, + to_recipients=[resp.email for resp in membership.team.responsible], formatdict=formatdict, subject='New membership request for {} at {}'.format( membership.team.name, diff --git a/src/teams/models.py b/src/teams/models.py index fd8aced4..7c82e5c5 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -3,9 +3,11 @@ from django.db.models.signals import post_save from django.dispatch import receiver from django.utils.text import slugify from utils.models import CampRelatedModel -from .email import send_new_membership_email +from .email import add_new_membership_email from django.core.exceptions import ValidationError from django.contrib.auth.models import User +import logging +logger = logging.getLogger("bornhack.%s" % __name__) class TeamArea(CampRelatedModel): @@ -96,6 +98,7 @@ class TeamMember(models.Model): @receiver(post_save, sender=TeamMember) -def send_responsible_email(sender, instance, created, **kwargs): +def add_responsible_email(sender, instance, created, **kwargs): if created: - send_new_membership_email(instance) + if not add_new_membership_email(instance): + logger.error('Error adding email to outgoing queue')