Added date selector to shuttles and traveller counts
This commit is contained in:
@@ -19,9 +19,9 @@ def bus_roll_context(queryset=None, include_bus_stops=True, date=None):
|
||||
|
||||
shuttle_routes = []
|
||||
for shuttle in Shuttle.objects.filter(bus=bus):
|
||||
shuttle_routes.append(shuttle_route_context(shuttle))
|
||||
shuttle_routes.append(shuttle_route_context(shuttle, date))
|
||||
|
||||
bus_routes.append({'bus': bus, 'route_stops': route_stops, 'shuttle_routes': shuttle_routes})
|
||||
bus_routes.append({'name': bus.route_name, 'traveller_count': bus.traveller_count(date), 'seating_capacity': bus.seating_capacity, 'bus': bus, 'route_stops': route_stops, 'shuttle_routes': shuttle_routes})
|
||||
if date is None:
|
||||
date = datetime.date.today()
|
||||
return {'routes': bus_routes, 'date': date.strftime('%Y-%m-%d')}
|
||||
@@ -115,10 +115,10 @@ def route_paged_context(bus, date=None):
|
||||
return route_stops
|
||||
|
||||
|
||||
def shuttle_route_context(shuttle):
|
||||
def shuttle_route_context(shuttle, date=None):
|
||||
shuttle_travellers = []
|
||||
for traveller in Traveller.objects.filter(shuttle=shuttle):
|
||||
if traveller._is_active():
|
||||
if traveller._is_active(date):
|
||||
shuttle_travellers.append({
|
||||
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school})",
|
||||
})
|
||||
|
||||
@@ -85,10 +85,10 @@ class Bus(models.Model):
|
||||
def __str__(self):
|
||||
return f"{self.route_name}"
|
||||
|
||||
def traveller_count(self):
|
||||
def traveller_count(self, date=None):
|
||||
count = 0
|
||||
for traveller in Traveller.objects.filter(bus_stops__bus=self):
|
||||
if traveller._is_active():
|
||||
if traveller._is_active(date):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
{% for route in routes %}
|
||||
{% if route.route_stops %}
|
||||
<h1 style="font-size: 2.5em">{{ route.bus.route_name }}</h1>
|
||||
<h1 style="font-size: 2.5em">{{ route.name }}</h1>
|
||||
<p style="text-align:right; font-size:12px">
|
||||
Date: {{ date }}<br>
|
||||
Total Travellers: {{ route.bus.traveller_count }}<br>
|
||||
Seating Capacity: {{ route.bus.seating_capacity }}
|
||||
Total Travellers: {{ route.traveller_count }}<br>
|
||||
Seating Capacity: {{ route.seating_capacity }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% for stop in route.route_stops %}
|
||||
|
||||
Reference in New Issue
Block a user