Opened 11 years ago
Closed 9 years ago
#21446 closed New feature (fixed)
Add possibility to not perform redirect in set_language view on AJAX requests
Reported by: | Krzysztof Jurewicz | Owned by: | Krzysztof Jurewicz |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
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 (11)
comment:1 by , 11 years ago
Has patch: | set |
---|
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → 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?
comment:3 by , 11 years ago
Triage Stage: | Accepted → Unreviewed |
---|
comment:4 by , 11 years ago
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 still 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/ .
comment:7 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:8 by , 11 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
I left comments for improvement on PR. Please uncheck "Patch needs improvement" when you update it, thanks.
comment:9 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 9 years ago
Summary: | Add possibility to not perform redirect in set_language view → Add possibility to not perform redirect in set_language view on AJAX requests |
---|---|
Triage Stage: | Accepted → Ready for checkin |
I’ve created a pull request: https://github.com/django/django/pull/1923