mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
* Upgrade django and stuff * Update to Django 2.2 and recent versions of similar packages * Provide explicit orderings to all models used in paginated queries * Resolve naive datetime warnings in test suite * Deal with deprecation warnings * Fix sqlparse version
28 lines
1018 B
Python
28 lines
1018 B
Python
from datetime import datetime, timedelta
|
|
|
|
from django.conf import settings
|
|
from django.http import HttpResponseRedirect
|
|
from django.utils.http import is_safe_url
|
|
from django.views.generic import View
|
|
|
|
from .robots import NoSearchIndexViewMixin
|
|
|
|
|
|
class LocaleSet(NoSearchIndexViewMixin, View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
url = request.GET.get('next', request.headers.get('Referer', '/'))
|
|
url = url if is_safe_url(url, allowed_hosts=[request.get_host()]) else '/'
|
|
resp = HttpResponseRedirect(url)
|
|
|
|
locale = request.GET.get('locale')
|
|
if locale in [lc for lc, ll in settings.LANGUAGES]:
|
|
|
|
max_age = 10 * 365 * 24 * 60 * 60
|
|
resp.set_cookie(settings.LANGUAGE_COOKIE_NAME, locale, max_age=max_age,
|
|
expires=(datetime.utcnow() + timedelta(seconds=max_age)).strftime(
|
|
'%a, %d-%b-%Y %H:%M:%S GMT'),
|
|
domain=settings.SESSION_COOKIE_DOMAIN)
|
|
|
|
return resp
|