newsletter not required
[edumed.git] / edumed / views.py
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
6 from .forms import AvatarlessEditProfileForm
7
8
9 class HomeView(TemplateView):
10     template_name = "home.html"
11
12
13 def mil_home_view(request):
14     return flatpage(request, url='/' if request.LANGUAGE_CODE == 'pl' else '/en/')
15
16
17 def mil_404_view(request):
18     return page_not_found(request, '404_mil.html')
19
20
21 def mil_contact_view(request):
22     return flatpage(request, url='/kontakt_mil/' if request.LANGUAGE_CODE == 'pl' else '/contact_mil/')
23
24
25 def mil_knowledge_base_view(request, url):
26     return flatpage(request, url='bazawiedzy/' + url)
27
28
29 def flatpage_with_template(request, url, template_name):
30     """
31     Public interface to the flat page view.
32
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.
36     Context:
37         flatpage
38             `flatpages.flatpages` object
39     """
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('/'):
47         url = '/' + url
48     site_id = get_current_site(request).id
49     try:
50         f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
51     except Http404:
52         if not url.endswith('/') and settings.APPEND_SLASH:
53             url += '/'
54             get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
55             return HttpResponsePermanentRedirect('%s/' % request.path)
56         else:
57             raise
58     f.template_name = template_name
59     return render_flatpage(request, f)