Skip to content

fix: resolve bulk upload Turbo error with PRG pattern#377

Merged
C4ptainCrunch merged 4 commits into
DocHub-ULB:mainfrom
mnietona:fix/bulk-upload-backend
Apr 23, 2026
Merged

fix: resolve bulk upload Turbo error with PRG pattern#377
C4ptainCrunch merged 4 commits into
DocHub-ULB:mainfrom
mnietona:fix/bulk-upload-backend

Conversation

@mnietona

@mnietona mnietona commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Description

Following your feedback, I investigated the Turbo console error instead of just disabling Turbo.

The Problem:
When the bulk upload form is submitted successfully, the submit_bulk view directly returns a render() (HTTP 200 OK). Hotwire Turbo strictly enforces the Post/Redirect/Get (PRG) pattern and throws the Form responses must redirect to another location error if a POST request doesn't return a redirect.

The Implemented Solution (Current PR):
I modified the view.py to respect the PRG pattern.

  1. On successful POST, it now returns an HttpResponseRedirect to the same URL, appending a ?success=1 parameter.
  2. The view catches this GET parameter and renders the existing document_bulk.html success page.
    Result: The console is perfectly clean, and Turbo handles the navigation smoothly.

Alternative Idea for the Future (Option B)

While this PR fixes the bug using the current UI, having a dedicated success page (document_bulk.html) and ?success=1 in the URL might feel a bit heavy.

As an alternative, we could completely remove this success page and use Django Flash Messages instead:

  • After a successful POST, we redirect the user straight back to the course page (or the upload form).
  • We display a global green success banner saying: "Merci ! Ton lien a bien été envoyé aux administrateurs pour traitement."

Let me know if you prefer to merge this PR as a quick fix, or if you'd like me to implement this "Flash Message" alternative instead!


Manual Testing:

  • Tested with a valid URL on local environment.
  • Verified that the Turbo console error is completely gone.

Fixes #369

Comment thread documents/views.py Outdated
@C4ptainCrunch

Copy link
Copy Markdown
Contributor

I prefer option A as users are often "blind" to banners and flash messages. If you could just address my 2 comments i'll merge this 👍

Applied maintainer feedback to use the query parameter in reverse() and handled success as a boolean. Improved UX by adding a specific error message for invalid links in the bulk upload form.
@mnietona

Copy link
Copy Markdown
Contributor Author

UX Improvement:
Added a targeted error message using ?error=bulk. This "flag" allows the HTML template to display a specific alert box right above the bulk upload field if the link is invalid, avoiding a silent redirect.

Comment thread documents/views.py Outdated
@C4ptainCrunch C4ptainCrunch merged commit d2adfa6 into DocHub-ULB:main Apr 23, 2026
2 checks passed
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.

[Bug] Bulk upload form submission is broken (Turbo conflict)

2 participants