Created new models to replicate out of and split coord app
Moved helpers and views to their respective new apps
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
from django.db.models import Q
|
||||
|
||||
from transport.models import Bus
|
||||
from traveller.models import TravellerRoute
|
||||
|
||||
|
||||
def school_roll_context(queryset, date=None):
|
||||
school_list = []
|
||||
|
||||
for school in queryset:
|
||||
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(date):
|
||||
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"
|
||||
shuttle_name = " "
|
||||
if traveller.shuttle:
|
||||
shuttle_name = traveller.shuttle.bus
|
||||
travellers.append({
|
||||
'display': display_name,
|
||||
'isFared': is_fared,
|
||||
'shuttle': shuttle_name,
|
||||
'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_route_context(traveller_route):
|
||||
traveller = traveller_route.traveller
|
||||
bus_stop = traveller_route.busStop
|
||||
families = traveller.get_families()
|
||||
address = ""
|
||||
for family in families:
|
||||
if address:
|
||||
address += ";"
|
||||
address = address + f"{family.residential_address} {family.residential_suburb}"
|
||||
return {
|
||||
'first_name': traveller.first_name,
|
||||
'last_name': traveller.last_name,
|
||||
'active': traveller.is_active,
|
||||
'school': traveller.school,
|
||||
'dob': traveller.dob,
|
||||
'year_level': traveller.year_level,
|
||||
'address': address,
|
||||
'start_date': traveller.travel_start_date,
|
||||
'end_date': traveller.travel_end_date,
|
||||
'eligibility': traveller.get_eligibility_status_display(),
|
||||
'shuttle': traveller.shuttle,
|
||||
'route': traveller_route.busStop.bus,
|
||||
'stop': f"#{bus_stop.get_stop_number()} - {bus_stop.address}",
|
||||
'pickup': bus_stop.am_time,
|
||||
'drop-off': bus_stop.pm_time
|
||||
}
|
||||
|
||||
def traveller_roll_context(queryset):
|
||||
travellers = []
|
||||
for traveller in queryset:
|
||||
for traveller_route in TravellerRoute.objects.filter(traveller=traveller):
|
||||
travellers.append(traveller_route_context(traveller_route))
|
||||
return travellers
|
||||
|
||||
def confirmation_letter_context(queryset):
|
||||
travellers = []
|
||||
for traveller in queryset:
|
||||
for travellerRoute in TravellerRoute.objects.filter(traveller=traveller):
|
||||
travellers.append({
|
||||
'traveller': traveller,
|
||||
'stop': travellerRoute.busStop,
|
||||
'shuttle': traveller.shuttle,
|
||||
})
|
||||
return {'travellers': travellers}
|
||||
Reference in New Issue
Block a user