Opened 21 months ago

Last modified 14 months ago

#21446 new New feature

Add possibility to not perform redirect in set_language view

Reported by: KJ Owned by: KJ
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

In set_language view, it should be possible to not perform redirect after request is made. Instead, a 204 status code could be returned. While performing a redirect was a reasonable behaviour in old times of HTML apps, for many AJAX applications it may be unnecessary and even uncomfortable if there is no good page become a redirect target.

Change History (8)

comment:1 Changed 21 months ago by KJ

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I’ve created a pull request: https://github.com/django/django/pull/1923

comment:2 Changed 20 months ago by apollo13

  • Triage Stage changed from Unreviewed to Accepted

I'd go even further, if there is no redirect parameter provided just return 204. Do all browsers etc support this properly?!

EDIT:// Thinking about this a bit more: since we change the language we have to redirect, how else would we change the UI?

Last edited 20 months ago by apollo13 (previous) (diff)

comment:3 Changed 20 months ago by apollo13

  • Triage Stage changed from Accepted to Unreviewed

comment:4 Changed 20 months ago by KJ

The project I’m currently working on uses Django as an API backend and AngularJS application as a frontend client to this API. The UI localization is done using Mozilla’s L20n project and language changing is done on-the-fly, without reloading the page. However there are some parts of the site which use Django templates (like password change form), so making an AJAX call to set_language is still necessary, but they are loaded using iframes, so there is no need to perform a redirect.

Not performing a redirect when it is not explicitly requested seems tempting, but it will be backwards incompatible with the current behaviour – I guess there may be a significant number of sites which rely on the fact that set_language redirects them to the previous page (captured from the referer header). Maybe we should check request.is_ajax() and if it is true, omit the redirect unless next parameter is set? For old-style HTML websites it may be still a coarsely correct assumption that a redirect needs to be performed after changing the language. That way we can resign from introducing the new no_redirect parameter.

204 status code seems to be supported by browsers, according to http://benramsey.com/blog/2008/05/http-status-204-no-content-and-205-reset-content/ .

Version 1, edited 20 months ago by KJ (previous) (next) (diff)

comment:5 Changed 20 months ago by aaugustin

This plan sounds good to me.

comment:6 Changed 20 months ago by KJ

I’ve updated the pull request accordingly.

comment:7 Changed 20 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:8 Changed 14 months ago by timo

  • Easy pickings unset
  • Patch needs improvement set

I left comments for improvement on PR. Please uncheck "Patch needs improvement" when you update it, thanks.

Note: See TracTickets for help on using tickets.
Back to Top