mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 09:00:33 +00:00
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 """
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
import dateutil.parser
|
||||
import dateutil.tz
|
||||
from dateutil.parser import ParserError
|
||||
|
||||
from requests import HTTPError
|
||||
from django.db.models import Q
|
||||
from django.conf import settings as django_settings
|
||||
from django.http import Http404
|
||||
from django.utils import translation
|
||||
|
||||
|
@ -186,7 +187,11 @@ def set_language(user, response):
|
|||
"""Updates a user's language"""
|
||||
if 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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue