Skip to content

Add Download Fleet CSV link to tabs#211

Open
shay-coding wants to merge 4 commits intomainfrom
shay-coding-patch-2
Open

Add Download Fleet CSV link to tabs#211
shay-coding wants to merge 4 commits intomainfrom
shay-coding-patch-2

Conversation

@shay-coding
Copy link
Collaborator

@shay-coding shay-coding commented Jan 7, 2026

Summary by CodeRabbit

  • New Features
    • Fleet vehicles can now be exported as CSV files, replacing the previous print option.
    • CSV export supports optional filtering by withdrawn status and depot location.
    • Active filters are automatically applied to exported data when selected.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Walkthrough

Replaces an owner-visible "Print Fleet" link with a "Download Fleet CSV" link in the vehicles tab, and adds an operator-scoped URL route for /operator/<operator_slug>/vehicles/export/; the template appends withdrawn and depot query parameters when present.

Changes

Cohort / File(s) Summary
Fleet Template Update
fleet/templates/partials/tabs.html
Replaced "Print Fleet" link with "Download Fleet CSV" linking to /operator/{{ operator.operator_slug }}/vehicles/export/. Added conditional query parameter logic for withdrawn and depot from request.GET. Kept owner-permission gating.
URL route
fleet/urls.py
Added new route operator/<str:operator_slug>/vehicles/export/ mapped to export_fleet_csv (name=export_fleet_csv) for CSV export.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped to the code with a curious squeak,
Swapped print for CSV — tidy and sleek,
Withdrawn and depot tucked in the query,
Download awaits, light and merry,
Fleet data ready — nibble, click, peek!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a new Download Fleet CSV link to the tabs template, replacing the previous Print Fleet link.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3433b9 and 2dcb36d.

📒 Files selected for processing (1)
  • fleet/urls.py
🧰 Additional context used
🪛 Ruff (0.14.10)
fleet/urls.py

100-100: export_fleet_csv may be undefined, or defined from star imports

(F405)

🔇 Additional comments (1)
fleet/urls.py (1)

1-2: The specific export route referenced does not exist in the current codebase.

The review references a new URL pattern at line 100 (path('operator/<str:operator_slug>/vehicles/export/', export_fleet_csv, ...)) and an export_fleet_csv view, but neither exist in the current fleet/urls.py or fleet/views.py. Line 100 in fleet/urls.py is blank, and no export_fleet_csv function is defined in fleet/views.py.

The general concern about star imports (from fleet.views import * at line 2) remains valid—this pattern can mask missing exports and violates linting rules—but cannot be verified against the specific route mentioned.

If this review is for a proposed change (PR/patch), ensure the referenced code is actually included in the changeset.

Likely an incorrect or invalid review comment.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In @fleet/templates/partials/tabs.html:
- 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.
- Around line 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.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a584c4 and a3433b9.

📒 Files selected for processing (1)
  • fleet/templates/partials/tabs.html

{% 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.

Comment on lines +47 to +53
<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 %}">
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants