registrasion/views.py
def invoice_mailout(request):
    ''' Allows staff to send emails to users based on their invoice status. '''

    category = request.GET.getlist("category", [])
    product = request.GET.getlist("product", [])
    status = request.GET.get("status")

    form = forms.InvoiceEmailForm(
        request.POST or None,
        category=category,
        product=product,
        status=status,
    )

    emails = []

    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,
                    "user": invoice.user,
                })
            )
            recipient_list = [invoice.user.email]
            emails.append(Email(subject, body, from_email, recipient_list))

        if form.cleaned_data["action"] == forms.InvoiceEmailForm.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/invoice_mailout.html", data)
def invoice_mailout(request):
    ''' Allows staff to send emails to users based on their invoice status. '''

    category = request.GET.getlist("category", [])
    product = request.GET.getlist("product", [])
    status = request.GET.get("status")

    form = forms.InvoiceEmailForm(
        request.POST or None,
        category=category,
        product=product,
        status=status,
    )

    emails = []

    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,
                    "user": invoice.user,
                })
            )
            recipient_list = [invoice.user.email]
            emails.append(Email(subject, body, from_email, recipient_list))

        if form.cleaned_data["action"] == forms.InvoiceEmailForm.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/invoice_mailout.html", data)
def invoice_mailout ( request ) : category = request . GET . getlist ( "category" , [ ] ) product = request . GET . getlist ( "product" , [ ] ) status = request . GET . get ( "status" ) form = forms . InvoiceEmailForm ( request . POST or None , category = category , product = product , status = status , ) emails = [ ] 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 , "user" : invoice . user , } ) ) recipient_list = [ invoice . user . email ] emails . append ( Email ( subject , body , from_email , recipient_list ) ) if form . cleaned_data [ "action" ] == forms . InvoiceEmailForm . 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/invoice_mailout.html" , data )
Allows staff to send emails to users based on their invoice status.
Allows staff to send emails to users based on their invoice status .