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
5 from pybb.views import ProfileEditView
7 from .forms import AvatarlessEditProfileForm
10 class HomeView(TemplateView):
11 template_name = "home.html"
14 def mil_home_view(request):
15 return flatpage(request, url='/' if request.LANGUAGE_CODE == 'pl' else '/en/')
18 def mil_404_view(request):
19 return page_not_found(request, '404_mil.html')
22 def mil_contact_view(request):
23 return flatpage(request, url='/kontakt_mil/' if request.LANGUAGE_CODE == 'pl' else '/contact_mil/')
26 def mil_knowledge_base_view(request, url):
27 return flatpage(request, url='bazawiedzy/' + url)
30 class AvatarlessProfileEditView(ProfileEditView):
31 form_class = AvatarlessEditProfileForm
34 def flatpage_with_template(request, url, template_name):
36 Public interface to the flat page view.
38 Models: `flatpages.flatpages`
39 Templates: Uses the template defined by the ``template_name`` field,
40 or :template:`flatpages/default.html` if template_name is not defined.
43 `flatpages.flatpages` object
45 from django.conf import settings
46 from django.contrib.flatpages.models import FlatPage
47 from django.contrib.flatpages.views import render_flatpage
48 from django.contrib.sites.models import get_current_site
49 from django.http.response import Http404, HttpResponsePermanentRedirect
50 from django.shortcuts import get_object_or_404
51 if not url.startswith('/'):
53 site_id = get_current_site(request).id
55 f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
57 if not url.endswith('/') and settings.APPEND_SLASH:
59 get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
60 return HttpResponsePermanentRedirect('%s/' % request.path)
63 f.template_name = template_name
64 return render_flatpage(request, f)