Adds functionality for sending nag e-mails

This commit is contained in:
Christopher Neugebauer 2016-12-07 17:31:42 +11:00
parent 051a942ffe
commit 19b59d7676
2 changed files with 21 additions and 1 deletions

View file

@ -402,7 +402,9 @@ class InvoiceNagForm(forms.Form):
widget=forms.CheckboxSelectMultiple,
queryset=commerce.Invoice.objects.all(),
)
message = forms.CharField(
from_email = forms.CharField()
subject = forms.CharField()
body = forms.CharField(
widget=forms.Textarea,
)

View file

@ -26,9 +26,11 @@ from django.contrib.auth.models import User
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ValidationError
from django.core.mail import send_mass_mail
from django.http import Http404
from django.shortcuts import redirect
from django.shortcuts import render
from django.template import Context, Template
_GuidedRegistrationSection = namedtuple(
@ -931,6 +933,22 @@ def nag_unpaid(request):
product=product,
)
if form.is_valid():
emails = []
for invoice in form.cleaned_data["invoice"]:
# datatuple = (subject, message, from_email, recipient_list)
from_email = form.cleaned_data["from_email"]
subject = form.cleaned_data["subject"]
body = Template(form.cleaned_data["body"]).render(
Context({
"invoice" : invoice,
})
)
recipient_list = [invoice.user.email]
emails.append((subject, body, from_email, recipient_list))
send_mass_mail(emails)
messages.info(request, "The e-mails have been sent.")
data = {
"form": form,
}