Opened 13 years ago

Closed 10 years ago

#15318 closed New feature (fixed)

A possibility to configure the language's cookie domain and expires.

Reported by: sahid Owned by: Sergey Kolosov
Component: Internationalization Version: 1.2
Severity: Normal Keywords: cookie, domain, language, settings
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

A suggest a new settings: LANGUAGE_COOKIE_DOMAIN

Index: conf/global_settings.py
===================================================================
--- conf/global_settings.py	(revision 15552)
+++ conf/global_settings.py	(working copy)
@@ -112,6 +112,8 @@
 USE_I18N = True
 LOCALE_PATHS = ()
 LANGUAGE_COOKIE_NAME = 'django_language'
+LANGUAGE_COOKIE_DOMAIN = None
+LANGUAGE_COOKIE_EXPIRES = None
 
 # If you set this to True, Django will format dates, numbers and calendars
 # according to user current locale
Index: views/i18n.py
===================================================================
--- views/i18n.py	(revision 15552)
+++ views/i18n.py	(working copy)
@@ -32,7 +32,11 @@
             if hasattr(request, 'session'):
                 request.session['django_language'] = lang_code
             else:
-                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
+                response.set_cookie(
+                    settings.LANGUAGE_COOKIE_NAME,
+                    lang_code,
+                    expires=settings.LANGUAGE_COOKIE_EXPIRES,
+                    domain=settings.LANGUAGE_COOKIE_DOMAIN)
     return response
 
 def get_formats():

Change History (11)

comment:1 by Russell Keith-Magee, 13 years ago

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Patch needs to be attached as a diff, rather than as a comment. It also requires tests.

comment:2 by Ramiro Morales, 13 years ago

Component: TranslationsInternationalization

comment:3 by Łukasz Rekucki, 13 years ago

Severity: Normal
Type: New feature

comment:4 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Sergey Kolosov, 11 years ago

Owner: changed from nobody to Sergey Kolosov
Status: newassigned

comment:7 by Sergey Kolosov, 11 years ago

Needs tests: unset
Patch needs improvement: unset

Pull request: https://github.com/django/django/pull/1150

For the sake of consistency I've added the following settings: LANGUAGE_COOKIE_AGE, LANGUAGE_COOKIE_PATH and LANGUAGE_COOKIE_DOMAIN.

comment:8 by Ramiro Morales, 11 years ago

This could be solved without introducing additional top-level settings if/after #21051 lands.

comment:9 by Tim Graham, 10 years ago

Patch needs improvement: set

I've left comments for improvement on the PR. Please uncheck "Patch needs improvement" when it's updated.

comment:10 by Sergey Kolosov, 10 years ago

Patch needs improvement: unset

comment:11 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 8c98f39624a60c63a16e097b64e5f71ecc27271f:

Fixed #15318 -- Added settings for language cookie max-age, path, domain

Introduced a number of settings to configure max-age, path, and domain
for the language cookie: LANGUAGE_COOKIE_AGE, LANGUAGE_COOKIE_PATH and
LANGUAGE_COOKIE_DOMAIN.

Thanks sahid for the suggestion.

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