Added function to email schools shuttle rolls.
This commit is contained in:
@@ -106,3 +106,31 @@ def email_school_roll(request, query_set):
|
||||
email.send(fail_silently=True)
|
||||
|
||||
return render_to_pdf(html_template, context)
|
||||
|
||||
|
||||
def email_school_shuttle_roll(request, queryset):
|
||||
html_template = 'reports/bus_roll.html'
|
||||
|
||||
schools = []
|
||||
for shuttle in queryset:
|
||||
if shuttle.school not in schools:
|
||||
schools.append(shuttle.school)
|
||||
for school in schools:
|
||||
buses = []
|
||||
for shuttle in queryset:
|
||||
if shuttle.school == school:
|
||||
buses.append(shuttle.bus)
|
||||
pdf = render_to_pdf(html_template, bus_roll_context(buses, include_bus_stops=False))
|
||||
|
||||
subject = "Echuca Schools Shuttle Roll"
|
||||
message = f"A new shuttle roll for {school.name} has been generated"
|
||||
email_from = "bus.manager@education.vic.gov.au"
|
||||
recipient = [school.email]
|
||||
email = EmailMessage(subject, message, email_from, recipient, _getBCC(request))
|
||||
email.attach(f"school_shuttle_roll_{date.today()}.pdf", pdf.content)
|
||||
email.send(fail_silently=True)
|
||||
buses = []
|
||||
for shuttle in queryset:
|
||||
if shuttle.bus not in buses:
|
||||
buses.append(shuttle.bus)
|
||||
return render_to_pdf(html_template, bus_roll_context(buses, include_bus_stops=False))
|
||||
|
||||
Reference in New Issue
Block a user