rename send email to add email and log on error

This commit is contained in:
Stephan Telling 2017-05-21 20:15:27 +02:00
parent c55c68beff
commit febecc137d
No known key found for this signature in database
GPG key ID: D4892289F36ADA9B
4 changed files with 18 additions and 16 deletions

View file

@ -15,7 +15,7 @@ def send_creditnote_email(creditnote):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/creditnote_email.txt', text_template='emails/creditnote_email.txt',
html_template='emails/creditnote_email.html', html_template='emails/creditnote_email.html',
recipients=creditnote.user.email, to_recipients=creditnote.user.email,
formatdict=formatdict, formatdict=formatdict,
subject=subject, subject=subject,
attachment=creditnote.pdf.read(), attachment=creditnote.pdf.read(),
@ -37,7 +37,7 @@ def send_invoice_email(invoice):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/invoice_email.txt', text_template='emails/invoice_email.txt',
html_template='emails/invoice_email.html', html_template='emails/invoice_email.html',
recipients=invoice.order.user.email, to_recipients=invoice.order.user.email,
formatdict=formatdict, formatdict=formatdict,
subject=subject, subject=subject,
attachment=invoice.pdf.read(), attachment=invoice.pdf.read(),
@ -48,6 +48,6 @@ def send_invoice_email(invoice):
def send_test_email(recipient): def send_test_email(recipient):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/testmail.txt', text_template='emails/testmail.txt',
recipients=recipient, to_recipients=recipient,
subject='testmail from bornhack website' subject='testmail from bornhack website'
) )

View file

@ -1,6 +1,6 @@
from django.contrib import admin from django.contrib import admin
from .models import Team, TeamArea, TeamMember 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) admin.site.register(TeamArea)
@ -41,7 +41,7 @@ class TeamMemberAdmin(admin.ModelAdmin):
membership.approved = True membership.approved = True
membership.save() membership.save()
updated += 1 updated += 1
send_add_membership_email(membership) add_added_membership_email(membership)
self.message_user( self.message_user(
request, request,
@ -57,7 +57,7 @@ class TeamMemberAdmin(admin.ModelAdmin):
updated = 0 updated = 0
for membership in queryset: for membership in queryset:
send_remove_membership_email(membership) add_removed_membership_email(membership)
membership.delete() membership.delete()
updated += 1 updated += 1
@ -69,4 +69,3 @@ class TeamMemberAdmin(admin.ModelAdmin):
) )
) )
remove_member.description = 'Remove a user from the team.' remove_member.description = 'Remove a user from the team.'

View file

@ -3,7 +3,7 @@ import logging
logger = logging.getLogger("bornhack.%s" % __name__) logger = logging.getLogger("bornhack.%s" % __name__)
def send_add_membership_email(membership): def add_added_membership_email(membership):
formatdict = { formatdict = {
'team': membership.team.name, 'team': membership.team.name,
'camp': membership.team.camp.title 'camp': membership.team.camp.title
@ -12,13 +12,13 @@ def send_add_membership_email(membership):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/add_membership_email.txt', text_template='emails/add_membership_email.txt',
html_template='emails/add_membership_email.html', html_template='emails/add_membership_email.html',
recipient=membership.user.email, to_recipients=membership.user.email,
formatdict=formatdict, formatdict=formatdict,
subject='Team update from {}'.format(membership.team.camp.title) subject='Team update from {}'.format(membership.team.camp.title)
) )
def send_remove_membership_email(membership): def add_removed_membership_email(membership):
formatdict = { formatdict = {
'team': membership.team.name, 'team': membership.team.name,
'camp': membership.team.camp.title 'camp': membership.team.camp.title
@ -34,13 +34,13 @@ def send_remove_membership_email(membership):
return add_outgoing_email( return add_outgoing_email(
text_template=text_template, text_template=text_template,
html_template=html_template, html_template=html_template,
recipient=membership.user.email, to_recipients=membership.user.email,
formatdict=formatdict, formatdict=formatdict,
subject='Team update from {}'.format(membership.team.camp.title) subject='Team update from {}'.format(membership.team.camp.title)
) )
def send_new_membership_email(membership): def add_new_membership_email(membership):
formatdict = { formatdict = {
'team': membership.team.name, 'team': membership.team.name,
'camp': membership.team.camp.title 'camp': membership.team.camp.title
@ -49,7 +49,7 @@ def send_new_membership_email(membership):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/new_membership_email.txt', text_template='emails/new_membership_email.txt',
html_template='emails/new_membership_email.html', html_template='emails/new_membership_email.html',
recipients=membership.team.responsible, to_recipients=[resp.email for resp in membership.team.responsible],
formatdict=formatdict, formatdict=formatdict,
subject='New membership request for {} at {}'.format( subject='New membership request for {} at {}'.format(
membership.team.name, membership.team.name,

View file

@ -3,9 +3,11 @@ from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.text import slugify from django.utils.text import slugify
from utils.models import CampRelatedModel 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.core.exceptions import ValidationError
from django.contrib.auth.models import User from django.contrib.auth.models import User
import logging
logger = logging.getLogger("bornhack.%s" % __name__)
class TeamArea(CampRelatedModel): class TeamArea(CampRelatedModel):
@ -96,6 +98,7 @@ class TeamMember(models.Model):
@receiver(post_save, sender=TeamMember) @receiver(post_save, sender=TeamMember)
def send_responsible_email(sender, instance, created, **kwargs): def add_responsible_email(sender, instance, created, **kwargs):
if created: if created:
send_new_membership_email(instance) if not add_new_membership_email(instance):
logger.error('Error adding email to outgoing queue')