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(
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'
)

View file

@ -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.'

View file

@ -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,

View file

@ -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')