data processing in forms
[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 from pybb.views import ProfileEditView
6
7 from .forms import AvatarlessEditProfileForm
8
9
10 class HomeView(TemplateView):
11     template_name = "home.html"
12
13
14 def mil_home_view(request):
15     return flatpage(request, url='/' if request.LANGUAGE_CODE == 'pl' else '/en/')
16
17
18 def mil_404_view(request):
19     return page_not_found(request, '404_mil.html')
20
21
22 def mil_contact_view(request):
23     return flatpage(request, url='/kontakt_mil/' if request.LANGUAGE_CODE == 'pl' else '/contact_mil/')
24
25
26 def mil_knowledge_base_view(request, url):
27     return flatpage(request, url='bazawiedzy/' + url)
28
29
30 class AvatarlessProfileEditView(ProfileEditView):
31     form_class = AvatarlessEditProfileForm
32
33
34 def flatpage_with_template(request, url, template_name):
35     """
36     Public interface to the flat page view.
37
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.
41     Context:
42         flatpage
43             `flatpages.flatpages` object
44     """
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('/'):
52         url = '/' + url
53     site_id = get_current_site(request).id
54     try:
55         f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
56     except Http404:
57         if not url.endswith('/') and settings.APPEND_SLASH:
58             url += '/'
59             get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
60             return HttpResponsePermanentRedirect('%s/' % request.path)
61         else:
62             raise
63     f.template_name = template_name
64     return render_flatpage(request, f)