Email roll to schools function
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from django.db.models import Q
|
||||
|
||||
from coord.models import Bus, BusStop, TravellerRoute, Driver, Traveller, Shuttle, School
|
||||
|
||||
|
||||
@@ -38,6 +40,48 @@ def bus_roll_context(queryset=None):
|
||||
return {'routes': bus_routes}
|
||||
|
||||
|
||||
def school_roll_context(queryset=None):
|
||||
school_list = []
|
||||
if queryset is None:
|
||||
schools = School.objects.all()
|
||||
else:
|
||||
schools = queryset
|
||||
|
||||
for school in schools:
|
||||
school_routes = []
|
||||
query = Q(traveller__school=school) | Q(traveller__shuttle__school=school)
|
||||
for bus in Bus.objects.all():
|
||||
travellers = []
|
||||
for trav_route in TravellerRoute.objects.filter(query).filter(busStop__bus=bus).order_by('busStop__am_time'):
|
||||
traveller = trav_route.traveller
|
||||
if not traveller.is_active():
|
||||
continue
|
||||
bus_stop = trav_route.busStop
|
||||
|
||||
display_name = f"{traveller} ({traveller.get_year_level_display()})"
|
||||
if traveller.school != school:
|
||||
display_name = f"{traveller} ({traveller.get_year_level_display()}, {traveller.school.shortName})"
|
||||
is_fared = "---"
|
||||
if traveller.eligibility_status == "2":
|
||||
is_fared = "Y"
|
||||
travellers.append({
|
||||
'display': display_name,
|
||||
'isFared': is_fared,
|
||||
'stop': f"#{bus_stop.get_stop_number()} - {bus_stop.address}",
|
||||
'am_time': bus_stop.am_time,
|
||||
'pm_time': bus_stop.pm_time
|
||||
})
|
||||
if travellers:
|
||||
school_routes.append({
|
||||
'bus': bus,
|
||||
'travellers': travellers
|
||||
})
|
||||
|
||||
|
||||
school_list.append({"name": school.name, "routes": school_routes})
|
||||
return {"schools": school_list}
|
||||
|
||||
|
||||
def traveller_roll_context(queryset):
|
||||
travellers = []
|
||||
for traveller in queryset:
|
||||
@@ -46,7 +90,7 @@ def traveller_roll_context(queryset):
|
||||
return travellers
|
||||
|
||||
|
||||
def school_roll_context(school):
|
||||
def school_travellerRoute_context(school):
|
||||
travellers = []
|
||||
for travellerRoute in TravellerRoute.objects.filter(traveller__school=school):
|
||||
traveller = travellerRoute.traveller
|
||||
|
||||
Reference in New Issue
Block a user