forked from mirrors/bookwyrm
Merge pull request #1792 from reesporte/lang-setting
save language preferences with cookies that last
This commit is contained in:
commit
b6d04e9997
1 changed files with 7 additions and 2 deletions
|
@ -1,12 +1,13 @@
|
||||||
""" helper functions used in various views """
|
""" helper functions used in various views """
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import dateutil.tz
|
import dateutil.tz
|
||||||
from dateutil.parser import ParserError
|
from dateutil.parser import ParserError
|
||||||
|
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.conf import settings as django_settings
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
|
@ -186,7 +187,11 @@ def set_language(user, response):
|
||||||
"""Updates a user's language"""
|
"""Updates a user's language"""
|
||||||
if user.preferred_language:
|
if user.preferred_language:
|
||||||
translation.activate(user.preferred_language)
|
translation.activate(user.preferred_language)
|
||||||
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user.preferred_language)
|
response.set_cookie(
|
||||||
|
settings.LANGUAGE_COOKIE_NAME,
|
||||||
|
user.preferred_language,
|
||||||
|
expires=datetime.now() + timedelta(seconds=django_settings.SESSION_COOKIE_AGE),
|
||||||
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue