Email bus rolls function uses company email field
This commit is contained in:
@@ -26,9 +26,10 @@ def email_companies_bus_roll(request, query_set=None):
|
|||||||
context = bus_roll_context(query_set)
|
context = bus_roll_context(query_set)
|
||||||
|
|
||||||
for company in Company.objects.all():
|
for company in Company.objects.all():
|
||||||
|
if not company.contact_email:
|
||||||
|
continue
|
||||||
company_route = []
|
company_route = []
|
||||||
for route in context.get("routes"):
|
for route in context.get("routes"):
|
||||||
bus = route.get("bus")
|
|
||||||
if route.get("bus").company == company:
|
if route.get("bus").company == company:
|
||||||
company_route.append(route)
|
company_route.append(route)
|
||||||
if not company_route:
|
if not company_route:
|
||||||
@@ -39,9 +40,9 @@ def email_companies_bus_roll(request, query_set=None):
|
|||||||
subject = "Echuca Schools Bus Roll"
|
subject = "Echuca Schools Bus Roll"
|
||||||
message = f"A new bus roll for {company.name} has been generated"
|
message = f"A new bus roll for {company.name} has been generated"
|
||||||
email_from = "bus.manager@education.vic.gov.au"
|
email_from = "bus.manager@education.vic.gov.au"
|
||||||
recipient = ["john.mullins@education.vic.gov.au", "nicole.edwards@education.vic.gov.au"]
|
recipient = [company.contact_email]
|
||||||
email = EmailMessage(subject, message, email_from, recipient)
|
email = EmailMessage(subject, message, email_from, recipient)
|
||||||
email.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
|
email.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
|
||||||
email.send()
|
email.send(fail_silently=True)
|
||||||
|
|
||||||
return render_to_pdf(html_template, context)
|
return render_to_pdf(html_template, context)
|
||||||
|
|||||||
Reference in New Issue
Block a user