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 Krzysztof Jurewicz, 11 years ago

Has patch: set

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

comment:2 by Florian Apolloner, 11 years ago

Triage Stage: UnreviewedAccepted

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

Version 0, edited 11 years ago by Florian Apolloner (next)

comment:3 by Florian Apolloner, 11 years ago

Triage Stage: AcceptedUnreviewed

comment:4 by Krzysztof Jurewicz, 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/ .

Last edited 11 years ago by Krzysztof Jurewicz (previous) (diff)

comment:5 by Aymeric Augustin, 11 years ago

This plan sounds good to me.

comment:6 by Krzysztof Jurewicz, 11 years ago

I’ve updated the pull request accordingly.

comment:7 by Aymeric Augustin, 11 years ago

Triage Stage: UnreviewedAccepted

comment:8 by Tim Graham, 10 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 Claude Paroz, 9 years ago

Patch needs improvement: unset

comment:10 by Tim Graham, 9 years ago

Summary: Add possibility to not perform redirect in set_language viewAdd possibility to not perform redirect in set_language view on AJAX requests
Triage Stage: AcceptedReady for checkin

comment:11 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 940b7fd5:

Fixed #21446 -- Allowed not performing redirect in set_language view

Thanks Claude Paroz and Tim Graham for polishing the patch.

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