Added date selector to shuttles and traveller counts

This commit is contained in:
John Mullins
2024-12-13 09:36:41 +11:00
parent 320303f95f
commit dabce7f360
3 changed files with 9 additions and 9 deletions
+4 -4
View File
@@ -19,9 +19,9 @@ def bus_roll_context(queryset=None, include_bus_stops=True, date=None):
shuttle_routes = [] shuttle_routes = []
for shuttle in Shuttle.objects.filter(bus=bus): 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: if date is None:
date = datetime.date.today() date = datetime.date.today()
return {'routes': bus_routes, 'date': date.strftime('%Y-%m-%d')} return {'routes': bus_routes, 'date': date.strftime('%Y-%m-%d')}
@@ -115,10 +115,10 @@ def route_paged_context(bus, date=None):
return route_stops return route_stops
def shuttle_route_context(shuttle): def shuttle_route_context(shuttle, date=None):
shuttle_travellers = [] shuttle_travellers = []
for traveller in Traveller.objects.filter(shuttle=shuttle): for traveller in Traveller.objects.filter(shuttle=shuttle):
if traveller._is_active(): if traveller._is_active(date):
shuttle_travellers.append({ shuttle_travellers.append({
'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school})", 'display': f"{traveller} ({traveller.get_year_level_display()}, {traveller.school})",
}) })
+2 -2
View File
@@ -85,10 +85,10 @@ class Bus(models.Model):
def __str__(self): def __str__(self):
return f"{self.route_name}" return f"{self.route_name}"
def traveller_count(self): def traveller_count(self, date=None):
count = 0 count = 0
for traveller in Traveller.objects.filter(bus_stops__bus=self): for traveller in Traveller.objects.filter(bus_stops__bus=self):
if traveller._is_active(): if traveller._is_active(date):
count += 1 count += 1
return count return count
@@ -19,11 +19,11 @@
{% for route in routes %} {% for route in routes %}
{% if route.route_stops %} {% 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"> <p style="text-align:right; font-size:12px">
Date: {{ date }}<br> Date: {{ date }}<br>
Total Travellers: {{ route.bus.traveller_count }}<br> Total Travellers: {{ route.traveller_count }}<br>
Seating Capacity: {{ route.bus.seating_capacity }} Seating Capacity: {{ route.seating_capacity }}
</p> </p>
{% endif %} {% endif %}
{% for stop in route.route_stops %} {% for stop in route.route_stops %}