2009-05-17 11:34:55 +00:00
|
|
|
# Create your views here.
|
2017-06-20 02:20:46 +00:00
|
|
|
from django.shortcuts import render
|
2011-12-14 13:17:31 +00:00
|
|
|
from django.conf import settings
|
2009-05-17 11:34:55 +00:00
|
|
|
from django import http
|
|
|
|
from django.utils import translation
|
2016-07-26 21:08:23 +00:00
|
|
|
from .models import Page
|
2009-05-17 11:34:55 +00:00
|
|
|
|
2014-10-04 09:22:47 +00:00
|
|
|
def page(request, page_to_render):
|
2011-12-14 13:14:09 +00:00
|
|
|
try:
|
2014-10-04 09:22:47 +00:00
|
|
|
p = Page.objects.get(slug=page_to_render, public=True)
|
2011-12-14 13:14:09 +00:00
|
|
|
except Page.DoesNotExist:
|
2017-06-20 02:20:46 +00:00
|
|
|
return render(request, "pages/{}.html".format(page_to_render),
|
|
|
|
{ "request" : request,},
|
2016-07-26 21:08:23 +00:00
|
|
|
)
|
2017-06-20 02:20:46 +00:00
|
|
|
return render(request, "page.html",
|
|
|
|
{ "request" : request, "page" : p, },
|
2011-12-14 13:14:09 +00:00
|
|
|
)
|
2009-05-17 11:34:55 +00:00
|
|
|
|
2014-10-04 09:22:47 +00:00
|
|
|
def langpage(request, lang, page_to_trans):
|
|
|
|
translation.activate(lang)
|
|
|
|
return page(request, page_to_trans)
|
2009-05-17 11:34:55 +00:00
|
|
|
|
|
|
|
def set_language(request):
|
2016-07-26 21:08:23 +00:00
|
|
|
next = request.POST.get('next', request.GET.get('next', None))
|
2009-05-17 11:34:55 +00:00
|
|
|
if not next:
|
|
|
|
next = request.META.get('HTTP_REFERER', None)
|
|
|
|
if not next:
|
|
|
|
next = '/'
|
|
|
|
response = http.HttpResponseRedirect(next)
|
|
|
|
if request.method == 'GET':
|
|
|
|
lang_code = request.GET.get('language', None)
|
|
|
|
if lang_code and translation.check_for_language(lang_code):
|
|
|
|
if hasattr(request, 'session'):
|
2017-06-16 20:17:49 +00:00
|
|
|
request.session[translation.LANGUAGE_SESSION_KEY] = lang_code
|
2009-05-17 11:34:55 +00:00
|
|
|
else:
|
|
|
|
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
|
|
|
|
return response
|
|
|
|
|