|
|
|
@ -7,12 +7,10 @@ from markdown.extensions.toc import TocExtension
|
|
|
|
|
from django.http import HttpResponseNotFound
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from django.utils.translation import ugettext as _, get_language
|
|
|
|
|
from django.utils.translation import gettext as _, get_language
|
|
|
|
|
from django import http
|
|
|
|
|
from django.utils.http import is_safe_url
|
|
|
|
|
from django.utils.translation import (
|
|
|
|
|
LANGUAGE_SESSION_KEY, check_for_language,
|
|
|
|
|
)
|
|
|
|
|
from django.utils.http import url_has_allowed_host_and_scheme
|
|
|
|
|
from django.utils.translation import check_for_language
|
|
|
|
|
from django.template.loader import TemplateDoesNotExist, get_template, select_template
|
|
|
|
|
from django.template import Template
|
|
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
@ -61,17 +59,24 @@ def set_lang(request):
|
|
|
|
|
""" django.views.i18n.set_language() with GET """
|
|
|
|
|
|
|
|
|
|
next = request.GET.get('next', request.GET.get('next'))
|
|
|
|
|
if not is_safe_url(url=next, allowed_hosts={request.get_host()}):
|
|
|
|
|
if not url_has_allowed_host_and_scheme(url=next, allowed_hosts={request.get_host()}):
|
|
|
|
|
next = request.META.get('HTTP_REFERER')
|
|
|
|
|
if not is_safe_url(url=next, allowed_hosts={request.get_host()}):
|
|
|
|
|
if not url_has_allowed_host_and_scheme(url=next, allowed_hosts={request.get_host()}):
|
|
|
|
|
next = '/'
|
|
|
|
|
response = http.HttpResponseRedirect(next)
|
|
|
|
|
lang_code = request.GET.get('lang', None)
|
|
|
|
|
if lang_code and check_for_language(lang_code):
|
|
|
|
|
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code,
|
|
|
|
|
|
|
|
|
|
response.set_cookie(
|
|
|
|
|
settings.LANGUAGE_COOKIE_NAME,
|
|
|
|
|
lang_code,
|
|
|
|
|
max_age=settings.LANGUAGE_COOKIE_AGE,
|
|
|
|
|
path=settings.LANGUAGE_COOKIE_PATH,
|
|
|
|
|
domain=settings.LANGUAGE_COOKIE_DOMAIN)
|
|
|
|
|
domain=settings.LANGUAGE_COOKIE_DOMAIN,
|
|
|
|
|
secure=settings.LANGUAGE_COOKIE_SECURE,
|
|
|
|
|
httponly=settings.LANGUAGE_COOKIE_HTTPONLY,
|
|
|
|
|
samesite=settings.LANGUAGE_COOKIE_SAMESITE,
|
|
|
|
|
)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|