Adds preview function to nag_unpaid
This commit is contained in:
parent
221b4d6a22
commit
06fe8a8ffa
2 changed files with 29 additions and 3 deletions
|
@ -414,6 +414,15 @@ def staff_products_formset_factory(user):
|
|||
|
||||
|
||||
class InvoiceNagForm(forms.Form):
|
||||
|
||||
ACTION_PREVIEW = 1
|
||||
ACTION_SEND = 2
|
||||
|
||||
ACTION_CHOICES = (
|
||||
(ACTION_PREVIEW, "Preview"),
|
||||
(ACTION_SEND, "Send emails"),
|
||||
)
|
||||
|
||||
invoice = forms.ModelMultipleChoiceField(
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
queryset=commerce.Invoice.objects.all(),
|
||||
|
@ -423,6 +432,12 @@ class InvoiceNagForm(forms.Form):
|
|||
body = forms.CharField(
|
||||
widget=forms.Textarea,
|
||||
)
|
||||
action = forms.TypedChoiceField(
|
||||
widget=forms.RadioSelect,
|
||||
coerce=int,
|
||||
choices=ACTION_CHOICES,
|
||||
initial=ACTION_PREVIEW,
|
||||
)
|
||||
|
||||
def __init__(self, *a, **k):
|
||||
category = k.pop('category', None) or []
|
||||
|
|
|
@ -920,6 +920,11 @@ def extend_reservation(request, user_id, days=7):
|
|||
return redirect(request.META["HTTP_REFERER"])
|
||||
|
||||
|
||||
Email = namedtuple(
|
||||
"Email",
|
||||
("subject", "body", "from_email", "recipient_list"),
|
||||
)
|
||||
|
||||
@user_passes_test(_staff_only)
|
||||
def nag_unpaid(request):
|
||||
''' Allows staff to nag users with unpaid invoices. '''
|
||||
|
@ -933,6 +938,8 @@ def nag_unpaid(request):
|
|||
product=product,
|
||||
)
|
||||
|
||||
emails = []
|
||||
|
||||
if form.is_valid():
|
||||
emails = []
|
||||
for invoice in form.cleaned_data["invoice"]:
|
||||
|
@ -945,12 +952,16 @@ def nag_unpaid(request):
|
|||
})
|
||||
)
|
||||
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.")
|
||||
emails.append(Email(subject, body, from_email, recipient_list))
|
||||
|
||||
if form.cleaned_data["action"] == forms.InvoiceNagForm.ACTION_SEND:
|
||||
# Send e-mails *ONLY* if we're sending.
|
||||
send_mass_mail(emails)
|
||||
messages.info(request, "The e-mails have been sent.")
|
||||
|
||||
data = {
|
||||
"form": form,
|
||||
"emails": emails,
|
||||
}
|
||||
|
||||
return render(request, "registrasion/nag_unpaid.html", data)
|
||||
|
|
Loading…
Reference in a new issue