1 # -*- coding: utf-8 -*-
2 from django.contrib.flatpages.views import flatpage
3 from django.views.defaults import page_not_found
4 from django.views.generic import TemplateView
6 from .forms import AvatarlessEditProfileForm
9 class HomeView(TemplateView):
10 template_name = "home.html"
13 def mil_home_view(request):
14 return flatpage(request, url='/' if request.LANGUAGE_CODE == 'pl' else '/en/')
17 def mil_404_view(request):
18 return page_not_found(request, '404_mil.html')
21 def mil_contact_view(request):
22 return flatpage(request, url='/kontakt_mil/' if request.LANGUAGE_CODE == 'pl' else '/contact_mil/')
25 def mil_knowledge_base_view(request, url):
26 return flatpage(request, url='bazawiedzy/' + url)
29 def flatpage_with_template(request, url, template_name):
31 Public interface to the flat page view.
33 Models: `flatpages.flatpages`
34 Templates: Uses the template defined by the ``template_name`` field,
35 or :template:`flatpages/default.html` if template_name is not defined.
38 `flatpages.flatpages` object
40 from django.conf import settings
41 from django.contrib.flatpages.models import FlatPage
42 from django.contrib.flatpages.views import render_flatpage
43 from django.contrib.sites.models import get_current_site
44 from django.http.response import Http404, HttpResponsePermanentRedirect
45 from django.shortcuts import get_object_or_404
46 if not url.startswith('/'):
48 site_id = get_current_site(request).id
50 f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
52 if not url.endswith('/') and settings.APPEND_SLASH:
54 get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
55 return HttpResponsePermanentRedirect('%s/' % request.path)
58 f.template_name = template_name
59 return render_flatpage(request, f)