2020-04-08 13:06:24 +00:00
|
|
|
from django.shortcuts import redirect, render
|
2020-01-22 17:32:13 +00:00
|
|
|
from django.utils.translation import LANGUAGE_SESSION_KEY
|
|
|
|
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
|
|
template_name = "frontend/index.html"
|
|
|
|
|
|
|
|
def change_language(request):
|
|
|
|
url = request.GET.get('url', '/')
|
|
|
|
language = request.GET.get('language', 'de')
|
|
|
|
if "://" in url:
|
|
|
|
raise ValueError("This is not a de-referer.")
|
|
|
|
request.session[LANGUAGE_SESSION_KEY] = language
|
|
|
|
return redirect(url)
|
2020-01-26 10:53:25 +00:00
|
|
|
|
|
|
|
def errorhandler(request, exception, status):
|
2020-04-08 13:06:24 +00:00
|
|
|
response = render(request, "frontend/error.html", {"status_code": status})
|
2020-01-26 10:53:25 +00:00
|
|
|
response.status_code = status
|
|
|
|
return response
|
|
|
|
|
|
|
|
def handler404(request, exception):
|
|
|
|
return errorhandler(request, exception, 404)
|
|
|
|
|
|
|
|
def handler500(request):
|
2020-04-08 13:06:24 +00:00
|
|
|
return errorhandler(request, None, 500)
|