Added date selector to rolls
This commit is contained in:
@@ -5,8 +5,7 @@ from django.db.models import Q
|
||||
from .models import Bus, BusStop, TravellerRoute, Driver, Traveller, Shuttle
|
||||
|
||||
|
||||
def bus_roll_context(queryset=None, include_bus_stops=True):
|
||||
date = datetime.date.today().strftime('%Y-%m-%d')
|
||||
def bus_roll_context(queryset=None, include_bus_stops=True, date=None):
|
||||
bus_routes = []
|
||||
if queryset is None:
|
||||
buses = Bus.objects.all()
|
||||
@@ -16,17 +15,19 @@ def bus_roll_context(queryset=None, include_bus_stops=True):
|
||||
for bus in buses:
|
||||
route_stops = []
|
||||
if include_bus_stops:
|
||||
route_stops = route_paged_context(bus)
|
||||
route_stops = route_paged_context(bus=bus, date=date)
|
||||
|
||||
shuttle_routes = []
|
||||
for shuttle in Shuttle.objects.filter(bus=bus):
|
||||
shuttle_routes.append(shuttle_route_context(shuttle))
|
||||
|
||||
bus_routes.append({'bus': bus, 'route_stops': route_stops, 'shuttle_routes': shuttle_routes})
|
||||
return {'routes': bus_routes, 'date': date}
|
||||
if date is None:
|
||||
date = datetime.date.today()
|
||||
return {'routes': bus_routes, 'date': date.strftime('%Y-%m-%d')}
|
||||
|
||||
|
||||
def school_roll_context(queryset):
|
||||
def school_roll_context(queryset, date=None):
|
||||
school_list = []
|
||||
|
||||
for school in queryset:
|
||||
@@ -36,7 +37,7 @@ def school_roll_context(queryset):
|
||||
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():
|
||||
if not traveller._is_active(date):
|
||||
continue
|
||||
bus_stop = trav_route.busStop
|
||||
|
||||
@@ -75,7 +76,7 @@ def traveller_roll_context(queryset):
|
||||
return travellers
|
||||
|
||||
|
||||
def route_paged_context(bus):
|
||||
def route_paged_context(bus, date=None):
|
||||
table_header_size = 5
|
||||
page_max_size = 45
|
||||
page_size = 3 # Account for traveller numbers at the top of the first page
|
||||
@@ -85,7 +86,7 @@ def route_paged_context(bus):
|
||||
traveller_list = []
|
||||
for trav_route in traveller_routes:
|
||||
traveller = trav_route.traveller
|
||||
if not traveller._is_active():
|
||||
if not traveller._is_active(date):
|
||||
continue
|
||||
is_fared = "---"
|
||||
if traveller.eligibility_status == "2":
|
||||
@@ -124,11 +125,11 @@ def shuttle_route_context(shuttle):
|
||||
return {'shuttle': shuttle, 'shuttle_travellers': shuttle_travellers}
|
||||
|
||||
|
||||
def school_travellerRoute_context(school):
|
||||
def school_travellerRoute_context(school, date=None):
|
||||
travellers = []
|
||||
for travellerRoute in TravellerRoute.objects.filter(traveller__school=school):
|
||||
traveller = travellerRoute.traveller
|
||||
if not traveller._is_active():
|
||||
if not traveller._is_active(date):
|
||||
continue
|
||||
travellers.append(traveller_route_context(travellerRoute))
|
||||
return travellers
|
||||
|
||||
Reference in New Issue
Block a user