Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fleet/templates/edit_operator.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
Show Livery Border
</label>

<label for="show_trip_id">
<input type="checkbox" name="show_trip_id" {% if operator.show_trip_id %}checked{% endif %}>
Show Trip IDs
</label>

Comment on lines +95 to +99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all references to show_trip_id in the codebase
rg -n -C3 '\bshow_trip_id\b'

Repository: NextStopLabs/MyBusTimes

Length of output: 3693


🏁 Script executed:

#!/bin/bash
# Check the edit_operator.html template for other checkbox patterns
rg -n "type=\"checkbox\"" fleet/templates/edit_operator.html -B2 -A2

# Find view or form handling for operator edits
fd -e py . fleet | xargs rg -l "show_trip_id|edit.*operator" | head -5

Repository: NextStopLabs/MyBusTimes

Length of output: 593


🏁 Script executed:

#!/bin/bash
# Find the operator edit view in fleet/views.py
rg -n "def.*operator\|show_trip_id\|show_livery_border" fleet/views.py -A5 -B2 | head -60

Repository: NextStopLabs/MyBusTimes

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Check the size and content of views.py
wc -l fleet/views.py
# Look for class-based views or functions handling operators
rg -n "class.*Operator\|def.*operator\|def post\|def patch\|def put" fleet/views.py | head -20

Repository: NextStopLabs/MyBusTimes

Length of output: 86


🏁 Script executed:

#!/bin/bash
# Search for operator-related API views/viewsets
rg -n "class.*Operator.*View" fleet/views.py

# Also check if there's a separate forms.py
fd -name "forms.py" fleet/

Repository: NextStopLabs/MyBusTimes

Length of output: 297


🏁 Script executed:

#!/bin/bash
# Search for operator-related API views/viewsets
rg "class.*Operator.*View" fleet/views.py

# Check if there's a separate forms.py
find fleet -name "forms.py"

# Look for how form/request data is handled for operators
rg -n "request.POST\|request.data" fleet/views.py | grep -i operator | head -10

Repository: NextStopLabs/MyBusTimes

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Check fleet/forms.py for operator form definition
wc -l fleet/forms.py
rg -n "class.*Operator.*Form\|show_trip_id\|show_livery_border" fleet/forms.py -B3 -A3

Repository: NextStopLabs/MyBusTimes

Length of output: 85


🏁 Script executed:

#!/bin/bash
# Read the entire forms.py file
cat -n fleet/forms.py

Repository: NextStopLabs/MyBusTimes

Length of output: 15873


🏁 Script executed:

#!/bin/bash
# Search for operator update/edit handlers in views.py
rg -n "MBTOperator\|def.*operator" fleet/views.py | head -30

# Also check if there's a URLs pattern that might give a clue
rg -n "edit.*operator\|operator.*edit" fleet/urls.py

Repository: NextStopLabs/MyBusTimes

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Read the edit_operator.html template to understand the form submission
head -150 fleet/templates/edit_operator.html | tail -60

# Also look for the form action
rg -n "<form\|action=" fleet/templates/edit_operator.html | head -10

Repository: NextStopLabs/MyBusTimes

Length of output: 2559


🏁 Script executed:

#!/bin/bash
# Find the opening form tag
head -100 fleet/templates/edit_operator.html | grep -n "<form" -A5

# Also check if this is a method POST or PUT
rg -n "<form" fleet/templates/edit_operator.html -A5

Repository: NextStopLabs/MyBusTimes

Length of output: 800


🏁 Script executed:

#!/bin/bash
# Find the view that renders this template
rg -n "edit_operator.html" fleet/

# Find the corresponding view in urls.py
rg -n "edit.*operator\|operator.*edit" fleet/urls.py

Repository: NextStopLabs/MyBusTimes

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Read the view function that renders edit_operator.html (around line 3964)
sed -n '3920,4050p' fleet/views.py

Repository: NextStopLabs/MyBusTimes

Length of output: 4641


🏁 Script executed:

#!/bin/bash
# Find the function definition - search backwards from line 3964
sed -n '3800,3970p' fleet/views.py | head -100

Repository: NextStopLabs/MyBusTimes

Length of output: 4423


🏁 Script executed:

#!/bin/bash
# Search for show_trip_id in the POST handler section (around line 3830-3920)
sed -n '3820,3920p' fleet/views.py | grep -n "show_trip_id"

# Also do a broader search in views.py
rg -n "show_trip_id" fleet/views.py

Repository: NextStopLabs/MyBusTimes

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Final confirmation - search entire codebase for any assignment to show_trip_id field
rg "show_trip_id\s*=" --type py

# Also check if there's any auto-save mechanism or middleware that might handle it
rg "request.POST\|request.data" fleet/views.py | grep -i "show_trip_id\|setattr\|__dict__"

Repository: NextStopLabs/MyBusTimes

Length of output: 135


Add missing POST handler and fix label association for the checkbox.

The checkbox field won't persist because the view's POST handler is missing the line to save show_trip_id from the form submission. The show_livery_border checkbox (line 91) has the same missing id attribute issue and is correctly saved with operator.show_livery_border = request.POST.get('show_livery_border') == 'on', but no equivalent code exists for show_trip_id.

Required fixes

In the template (fleet/templates/edit_operator.html, lines 95-99), add the missing id attribute:

     <label for="show_trip_id">
-    <input type="checkbox" name="show_trip_id" {% if operator.show_trip_id %}checked{% endif %}>
+    <input type="checkbox" id="show_trip_id" name="show_trip_id" {% if operator.show_trip_id %}checked{% endif %}>
     Show Trip IDs
     </label>

In the POST handler (fleet/views.py, near where show_livery_border is set), add:

operator.show_trip_id = request.POST.get('show_trip_id') == 'on'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<label for="show_trip_id">
<input type="checkbox" name="show_trip_id" {% if operator.show_trip_id %}checked{% endif %}>
Show Trip IDs
</label>
<label for="show_trip_id">
<input type="checkbox" id="show_trip_id" name="show_trip_id" {% if operator.show_trip_id %}checked{% endif %}>
Show Trip IDs
</label>
🤖 Prompt for AI Agents
In `@fleet/templates/edit_operator.html` around lines 95 - 99, The template
checkbox for show_trip_id needs an id and its label should use
for="show_trip_id" (do the same for the show_livery_border checkbox to ensure
labels are associated), and in the view add the POST handler line
operator.show_trip_id = request.POST.get('show_trip_id') == 'on' next to where
operator.show_livery_border is set so the checkbox value is persisted after form
submit.

<button style="min-width: 150px;" class="btn delete-btn" type="button"
onclick='window.location.href="{% url 'reset_operator' operator.operator_slug %}"'>Reset Fleet</button>

Expand All @@ -117,4 +122,4 @@
{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/narrow.css' %}">
<link rel="stylesheet" href="{% static 'css/select2.css' %}">
{% endblock %}
{% endblock %}
64 changes: 35 additions & 29 deletions fleet/templates/vehicle_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,34 +239,40 @@ <h1>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th scope="col">Route</th>
<th scope="col" colspan="2">Trip</th>
<th scope="col">To</th>
{% if show_board %}
<th scope="col"></th>
{% endif %}
</tr>
</thead>
<tbody>
{% for trip in trips %}
<tr id="journey-{{ trip.pk }}" class="{% if trip.trip_missed %}missed{% endif %} {% if trip.trip_start_at > now %}early{% endif %}">
<td class="link">
{% if trip.trip_route.route_num %}
<a href="/operator/{{ operator.operator_slug }}/route/{{ trip.trip_route.id }}/#{{ trip.trip_start_at|date:"H:i" }}">{{ trip.trip_route.route_num }}</a>
{% else %}
{{ trip.trip_route_num }}
{% endif %}
</td>
<td class="tabular">{% if trip.trip_display_id %}{{ trip.trip_display_id }}{% else %}{{ trip.pk }}{% endif %}</td>
<td class="link tabular">
{% if trip.trip_route.route_num %}
<a href="/operator/{{ operator.operator_slug }}/route/{{ trip.trip_route.id }}/#{{ trip.trip_start_at|date:"H:i" }}">{{ trip.trip_start_at|date:"H:i" }}</a>
{% else %}
{{ trip.trip_start_at|date:"H:i" }}
{% endif %}
</td>
<td>{{ trip.trip_end_location }}</td>
<tr>
<th scope="col">Route</th>
{% if operator.show_trip_id %}
<th scope="col" colspan="2">Trip</th>
{% else %}
<th scope="col">Time</th>
{% endif %}
<th scope="col">To</th>
{% if show_board %}
<th scope="col"></th>
{% endif %}
</tr>
</thead>
<tbody>
{% for trip in trips %}
<tr id="journey-{{ trip.pk }}" class="{% if trip.trip_missed %}missed{% endif %} {% if trip.trip_start_at > now %}early{% endif %}">
<td class="link">
{% if trip.trip_route.route_num %}
<a href="/operator/{{ operator.operator_slug }}/route/{{ trip.trip_route.id }}/#{{ trip.trip_start_at|date:"H:i" }}">{{ trip.trip_route.route_num }}</a>
{% else %}
{{ trip.trip_route_num }}
{% endif %}
</td>
{% if operator.show_trip_id %}
<td class="tabular">{% if trip.trip_display_id %}{{ trip.trip_display_id }}{% else %}{{ trip.pk }}{% endif %}</td>
{% endif %}
<td class="link tabular">
{% if trip.trip_route.route_num %}
<a href="/operator/{{ operator.operator_slug }}/route/{{ trip.trip_route.id }}/#{{ trip.trip_start_at|date:"H:i" }}">{{ trip.trip_start_at|date:"H:i" }}</a>
{% else %}
{{ trip.trip_start_at|date:"H:i" }}
{% endif %}
</td>
<td>{{ trip.trip_end_location }}</td>
{% if show_board %}
{% if trip.trip_board.board_type == "duty" %}
<td><a href="/operator/{{ operator.operator_slug }}/duty/{{ trip.trip_board.id }}/">{{ trip.trip_board.duty_name }}</a></td>
Expand Down Expand Up @@ -308,4 +314,4 @@ <h1>
{% endif %}
</nav>

{% endblock %}
{% endblock %}
3 changes: 2 additions & 1 deletion fleet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3856,6 +3856,7 @@ def operator_edit(request, operator_slug):
operator.region.set(region_ids)

operator.show_livery_border = request.POST.get('show_livery_border') == 'on'
operator.show_trip_id = request.POST.get('show_trip_id') == 'on'
Comment on lines 3858 to +3859
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Include show_trip_id in the operator change audit log.

You now update operator.show_trip_id, but the change-tracking loop later doesn’t include this field, so toggles won’t be logged to Discord. Consider adding it to the changes list to keep the audit trail complete.

🤖 Prompt for AI Agents
In `@fleet/views.py` around lines 3858 - 3859, The change-tracking loop that
builds the `changes` list doesn't include `show_trip_id`, so toggles to that
field aren't recorded; update the logic that compares old vs new operator
attributes (the same place where `show_livery_border` is handled) to include
`show_trip_id` in the `changes` list when its value changes so the audit
log/Discord message reflects toggles to `operator.show_trip_id`.


if request.POST.get('group', None) == "":
group_instance = None
Expand Down Expand Up @@ -7249,4 +7250,4 @@ def boards_api(request, operator_slug):
'type': board.board_type
})

return JsonResponse({'results': results})
return JsonResponse({'results': results})