Added function to email schools shuttle rolls.
This commit is contained in:
@@ -13,7 +13,7 @@ from rangefilter.filters import DateRangeFilterBuilder
|
|||||||
from .adminClone import CloneModelAdmin
|
from .adminClone import CloneModelAdmin
|
||||||
from .context_helpers import *
|
from .context_helpers import *
|
||||||
from .email_helpers import email_companies_bus_roll, render_to_pdf, email_school_roll, \
|
from .email_helpers import email_companies_bus_roll, render_to_pdf, email_school_roll, \
|
||||||
email_companies_emergency_contacts
|
email_companies_emergency_contacts, email_school_shuttle_roll
|
||||||
from .forms import roll_date_selector
|
from .forms import roll_date_selector
|
||||||
from .models import *
|
from .models import *
|
||||||
from .utils.send_sms import send_sms
|
from .utils.send_sms import send_sms
|
||||||
@@ -62,6 +62,10 @@ class ShuttleRollMixin:
|
|||||||
buses.append(shuttle.bus)
|
buses.append(shuttle.bus)
|
||||||
return render_to_pdf('reports/bus_roll.html', bus_roll_context(buses, include_bus_stops=False))
|
return render_to_pdf('reports/bus_roll.html', bus_roll_context(buses, include_bus_stops=False))
|
||||||
|
|
||||||
|
def email_shuttle_roll(self, request, queryset):
|
||||||
|
return email_school_shuttle_roll(request, queryset)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SchoolRollMixin:
|
class SchoolRollMixin:
|
||||||
|
|
||||||
@@ -295,7 +299,7 @@ class SettingAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
|||||||
@admin.register(Shuttle)
|
@admin.register(Shuttle)
|
||||||
class ShuttleAdmin(MyImportExportModelAdmin, admin.ModelAdmin, ShuttleRollMixin):
|
class ShuttleAdmin(MyImportExportModelAdmin, admin.ModelAdmin, ShuttleRollMixin):
|
||||||
list_display = ["__str__", "school", "bus", "shuttle_travellers"]
|
list_display = ["__str__", "school", "bus", "shuttle_travellers"]
|
||||||
actions = ["show_shuttle_roll"]
|
actions = ["show_shuttle_roll", "email_shuttle_roll"]
|
||||||
|
|
||||||
def shuttle_travellers(self, obj):
|
def shuttle_travellers(self, obj):
|
||||||
url = (
|
url = (
|
||||||
|
|||||||
@@ -106,3 +106,31 @@ def email_school_roll(request, query_set):
|
|||||||
email.send(fail_silently=True)
|
email.send(fail_silently=True)
|
||||||
|
|
||||||
return render_to_pdf(html_template, context)
|
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