Bus roll stops page together
This commit is contained in:
@@ -4,6 +4,8 @@ from coord.models import Bus, BusStop, TravellerRoute, Driver, Traveller, Shuttl
|
|||||||
|
|
||||||
|
|
||||||
def bus_roll_context(queryset=None):
|
def bus_roll_context(queryset=None):
|
||||||
|
table_header_size = 5
|
||||||
|
page_max_size = 45
|
||||||
bus_routes = []
|
bus_routes = []
|
||||||
if queryset is None:
|
if queryset is None:
|
||||||
buses = Bus.objects.all()
|
buses = Bus.objects.all()
|
||||||
@@ -11,10 +13,21 @@ def bus_roll_context(queryset=None):
|
|||||||
buses = queryset
|
buses = queryset
|
||||||
|
|
||||||
for bus in buses:
|
for bus in buses:
|
||||||
bus_route = []
|
route_pages = []
|
||||||
|
page_stops = []
|
||||||
|
page_size = 0
|
||||||
for bus_stop in BusStop.objects.filter(bus=bus):
|
for bus_stop in BusStop.objects.filter(bus=bus):
|
||||||
|
traveller_routes = TravellerRoute.objects.filter(busStop=bus_stop)
|
||||||
|
page_size += table_header_size + traveller_routes.count()
|
||||||
|
if page_size > page_max_size:
|
||||||
|
route_pages.append({
|
||||||
|
'stops': page_stops
|
||||||
|
})
|
||||||
|
page_stops = []
|
||||||
|
page_size = table_header_size + traveller_routes.count()
|
||||||
|
|
||||||
traveller_list = []
|
traveller_list = []
|
||||||
for trav_route in TravellerRoute.objects.filter(busStop=bus_stop):
|
for trav_route in traveller_routes:
|
||||||
traveller = trav_route.traveller
|
traveller = trav_route.traveller
|
||||||
if not traveller.is_active():
|
if not traveller.is_active():
|
||||||
continue
|
continue
|
||||||
@@ -25,14 +38,13 @@ def bus_roll_context(queryset=None):
|
|||||||
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school.shortName})",
|
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school.shortName})",
|
||||||
'isFared': is_fared
|
'isFared': is_fared
|
||||||
})
|
})
|
||||||
stop_result = {
|
page_stops.append({
|
||||||
'stop_num': bus_stop.get_stop_number(),
|
'stop_num': bus_stop.get_stop_number(),
|
||||||
'name': bus_stop.address,
|
'name': bus_stop.address,
|
||||||
'am': bus_stop.am_time,
|
'am': bus_stop.am_time,
|
||||||
'pm': bus_stop.pm_time,
|
'pm': bus_stop.pm_time,
|
||||||
'travellers': traveller_list
|
'travellers': traveller_list
|
||||||
}
|
})
|
||||||
bus_route.append(stop_result)
|
|
||||||
|
|
||||||
shuttle_travellers = []
|
shuttle_travellers = []
|
||||||
has_shuttle = False
|
has_shuttle = False
|
||||||
@@ -43,7 +55,7 @@ def bus_roll_context(queryset=None):
|
|||||||
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school})",
|
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school})",
|
||||||
})
|
})
|
||||||
|
|
||||||
bus_routes.append({'bus': bus, 'stops': bus_route, 'has_shuttle': has_shuttle, 'shuttle_travellers': shuttle_travellers})
|
bus_routes.append({'route_name': bus.route_name, 'route_pages': route_pages, 'has_shuttle': has_shuttle, 'shuttle_travellers': shuttle_travellers})
|
||||||
return {'routes': bus_routes}
|
return {'routes': bus_routes}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +96,6 @@ def school_roll_context(queryset):
|
|||||||
'travellers': travellers
|
'travellers': travellers
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
school_list.append({"name": school.name, "routes": school_routes})
|
school_list.append({"name": school.name, "routes": school_routes})
|
||||||
return {"schools": school_list}
|
return {"schools": school_list}
|
||||||
|
|
||||||
|
|||||||
@@ -18,58 +18,59 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
{% for route in routes %}
|
{% for route in routes %}
|
||||||
<h1 style="font-size: 2.5em">{{ route.bus.route_name }}</h1>
|
{% for page in route.route_pages %}
|
||||||
{% for stop in route.stops %}
|
<h1 style="font-size: 2.5em">{{ route.route_name }}</h1>
|
||||||
<hr style="border: 5px">
|
{% for stop in page.stops %}
|
||||||
<table class="stopHeader">
|
<table class="stopHeader">
|
||||||
<tr>
|
|
||||||
<th style="width: 100%">Stop Number #{{ stop.stop_num }}</th>
|
|
||||||
<th style="width: 20%">Pickup Time</th>
|
|
||||||
<th style="width: 25%">Drop-off Time</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{{ stop.name }}</td>
|
|
||||||
<td>{{ stop.am }}</td>
|
|
||||||
<td>{{ stop.pm }}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<table class="traveller">
|
|
||||||
<tr>
|
|
||||||
<th style="width: 100%; text-align: left">Student</th>
|
|
||||||
<th style="width: 10%">Fare</th>
|
|
||||||
<th style="width: 8%">Mon AM</th>
|
|
||||||
<th style="width: 8%">Mon PM</th>
|
|
||||||
<th style="width: 8%">Tue AM</th>
|
|
||||||
<th style="width: 8%">Tue PM</th>
|
|
||||||
<th style="width: 8%">Wed AM</th>
|
|
||||||
<th style="width: 8%">Wed PM</th>
|
|
||||||
<th style="width: 8%">Thu AM</th>
|
|
||||||
<th style="width: 8%">Thu PM</th>
|
|
||||||
<th style="width: 8%">Fri AM</th>
|
|
||||||
<th style="width: 8%">Fri PM</th>
|
|
||||||
</tr>
|
|
||||||
{% for traveller in stop.travellers %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding-top: 3px; padding-left: 2px; text-align: left">{{ traveller.display }}</td>
|
<th style="width: 100%"></th>
|
||||||
<td style="padding-top: 3px; text-align: center"><b>{{ traveller.isFared }}</b></td>
|
<th style="width: 20%">Pickup Time</th>
|
||||||
<td> </td>
|
<th style="width: 25%">Drop-off Time</th>
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
<td> </td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
<tr>
|
||||||
</table>
|
<td><b>Stop Number #{{ stop.stop_num }}</b> {{ stop.name }}</td>
|
||||||
<br>
|
<td>{{ stop.am }}</td>
|
||||||
|
<td>{{ stop.pm }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<table class="traveller">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 100%; text-align: left">Student</th>
|
||||||
|
<th style="width: 10%">Fare</th>
|
||||||
|
<th style="width: 8%">Mon AM</th>
|
||||||
|
<th style="width: 8%">Mon PM</th>
|
||||||
|
<th style="width: 8%">Tue AM</th>
|
||||||
|
<th style="width: 8%">Tue PM</th>
|
||||||
|
<th style="width: 8%">Wed AM</th>
|
||||||
|
<th style="width: 8%">Wed PM</th>
|
||||||
|
<th style="width: 8%">Thu AM</th>
|
||||||
|
<th style="width: 8%">Thu PM</th>
|
||||||
|
<th style="width: 8%">Fri AM</th>
|
||||||
|
<th style="width: 8%">Fri PM</th>
|
||||||
|
</tr>
|
||||||
|
{% for traveller in stop.travellers %}
|
||||||
|
<tr>
|
||||||
|
<td style="padding-top: 3px; padding-left: 2px; text-align: left">{{ traveller.display }}</td>
|
||||||
|
<td style="padding-top: 3px; text-align: center"><b>{{ traveller.isFared }}</b></td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
<p style="page-break-after: always">
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if route.has_shuttle %}
|
{% if route.has_shuttle %}
|
||||||
<p style="page-break-after: always">
|
<h1 style="font-size: 2.5em">{{ route.route_name }} (Shuttle)</h1>
|
||||||
<h1 style="font-size: 2.5em">{{ route.bus.route_name }} (Shuttle)</h1>
|
|
||||||
<table class="traveller">
|
<table class="traveller">
|
||||||
{% for traveller in route.shuttle_travellers %}
|
{% for traveller in route.shuttle_travellers %}
|
||||||
<tr>
|
<tr>
|
||||||
@@ -77,6 +78,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
<p style="page-break-after: always">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p style="page-break-after: always">
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
Reference in New Issue
Block a user