Skip to content
Open
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
14 changes: 12 additions & 2 deletions fleet/templates/partials/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,18 @@
<li class="chip"><a href="/tracking/{{ operator.operator_slug }}/start/">Test Live Tracking</a></li>
{% endif %}
{% if 'owner' in helper_permissions %}
<li class="chip"><a href="#" onclick="printTable()">Print Fleet</a></li>
{% endif %}
<li>
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

Add class="chip" for styling consistency.

The <li> tag on line 46 is missing the class="chip" attribute that all other list items in this section use (see lines 28, 31, 34, 37, 40, 43). This creates a visual inconsistency.

🎨 Proposed fix
-<li>
+<li class="chip">
   <a href="/operator/{{ operator.operator_slug }}/vehicles/export/

Also applies to: 56-56

🤖 Prompt for AI Agents
In @fleet/templates/partials/tabs.html at line 46, In the tabs.html template,
two bare <li> elements are missing the class attribute; update those <li> tags
to include class="chip" so they match the other list items (which already use
class="chip") and restore visual consistency across the tab list.

<a href="/operator/{{ operator.operator_slug }}/vehicles/export/
{% if request.GET.withdrawn or request.GET.depot %}?{% endif %}
{% if request.GET.withdrawn %}withdrawn={{ request.GET.withdrawn }}{% endif %}
{% if request.GET.depot %}
{% if request.GET.withdrawn %}&{% endif %}
depot={{ request.GET.depot }}
{% endif %}">
Comment on lines +47 to +53
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 | 🟠 Major

Refactor URL construction to prevent whitespace and use proper encoding.

The multiline URL construction has two concerns:

  1. Whitespace injection: Splitting the URL across multiple lines may introduce unwanted whitespace in the rendered href, potentially breaking the link.
  2. Missing URL encoding: Query parameter values from request.GET.withdrawn and request.GET.depot are inserted directly without URL encoding. If these values contain special characters (spaces, &, =, etc.), the URL will be malformed.
🔧 Proposed fix using Django's url encoding
-  <a href="/operator/{{ operator.operator_slug }}/vehicles/export/
-    {% if request.GET.withdrawn or request.GET.depot %}?{% endif %}
-    {% if request.GET.withdrawn %}withdrawn={{ request.GET.withdrawn }}{% endif %}
-    {% if request.GET.depot %}
-      {% if request.GET.withdrawn %}&{% endif %}
-      depot={{ request.GET.depot }}
-    {% endif %}">
+  <a href="/operator/{{ operator.operator_slug }}/vehicles/export/?{% if request.GET.withdrawn %}withdrawn={{ request.GET.withdrawn|urlencode }}{% endif %}{% if request.GET.depot %}{% if request.GET.withdrawn %}&{% endif %}depot={{ request.GET.depot|urlencode }}{% endif %}">

Or better yet, build the query string in the view and pass it to the template, or use Django's {% url %} tag with query parameters.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In @fleet/templates/partials/tabs.html around lines 47 - 53, Refactor the
multiline href so it won’t introduce whitespace and so GET values are
URL-encoded: remove the line breaks around the href and either (a) use Django's
urlencode filter on the variables when building the query in-template (e.g. use
a single-line href and include withdrawn={{ request.GET.withdrawn|urlencode }}
and depot={{ request.GET.depot|urlencode }} only when present), or (b)
better—construct the query string in the view (e.g. export_query or export_qs)
and pass it into the template and use a single-line href like "/operator/{{
operator.operator_slug }}/vehicles/export/{{ '?' if export_query }}{{
export_query }}". Ensure you reference operator.operator_slug and
request.GET.withdrawn/request.GET.depot when replacing the current code.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find the view handling the vehicles export endpoint and verify parameter handling

# Search for URL pattern definition
echo "=== Searching for export URL pattern ==="
rg -n "vehicles/export" --type=py -C3

# Search for view function/class handling export
echo -e "\n=== Searching for export view implementation ==="
rg -n "def.*export|class.*Export" --type=py -C5 | rg -A5 -B5 "vehicle|fleet"

# Search for CSV export related code
echo -e "\n=== Searching for CSV export logic ==="
rg -n "csv|CSV" --type=py -C3 | rg -A3 -B3 "vehicle|fleet"

Repository: NextStopLabs/MyBusTimes

Length of output: 11884


🏁 Script executed:

#!/bin/bash
# Search for URL configuration files in fleet app
echo "=== Searching for URL routing files ==="
find . -name "urls.py" -type f | head -20

echo -e "\n=== Checking fleet app urls.py ==="
cat -n fleet/urls.py 2>/dev/null || echo "File not found"

echo -e "\n=== Searching for views in fleet app ==="
find fleet -name "views.py" -type f -exec echo "File: {}" \; -exec cat -n {} \;

echo -e "\n=== Searching for operator-related views ==="
rg -n "operator.*vehicles|vehicles.*export" --type=py -A5 -B5

echo -e "\n=== Searching for any export function ==="
rg -n "def export|class.*Export" --type=py -A10

Repository: NextStopLabs/MyBusTimes

Length of output: 50380


🏁 Script executed:

#!/bin/bash
# Search for export-related functions in views
echo "=== Searching for export functions in views ==="
rg -n "def.*export" fleet/views.py

# Also search more broadly
echo -e "\n=== Checking if vehicles_export function exists ==="
rg -n "vehicles.*export|export.*vehicle" --type=py

# Search for CSV writing in views
echo -e "\n=== Looking for HttpResponse with CSV content type ==="
rg -n "text/csv|csv.*response" --type=py

Repository: NextStopLabs/MyBusTimes

Length of output: 223


The /operator/<slug>/vehicles/export/ endpoint does not exist and must be implemented.

The template constructs a link to this endpoint with withdrawn and depot query parameters, but the URL pattern is missing from fleet/urls.py and no corresponding view handler exists. Create the endpoint, implement the view to filter vehicles based on these parameters, and generate CSV export output.

Download Fleet CSV
</a>
</li>
{% endif %}
</ul>
</div>
{% endif %}
Expand Down