Skip to content

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

Open
mnietona wants to merge 1 commit intoDocHub-ULB:mainfrom
mnietona:fix/bulk-upload-backend
Open

fix: resolve bulk upload Turbo error with PRG pattern#377
mnietona wants to merge 1 commit intoDocHub-ULB:mainfrom
mnietona:fix/bulk-upload-backend

Conversation

@mnietona
Copy link
Copy Markdown
Contributor

@mnietona mnietona commented Mar 29, 2026

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

"course": course,
},
success_url = (
reverse("document_submit_bulk", args=[course.slug]) + "?success=1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use the query parameter of reverse instead of crafting the url by hand: https://docs.djangoproject.com/en/6.0/ref/urlresolvers/#reverse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, could you try to have only ?success if possible ? Probably by treating it as a boolean

@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 👍

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