1ba6137d7632f13be3aea2f78b2ed4477c57f236
[edumed.git] / edumed / views.py
1 # -*- coding: utf-8 -*-
2 from django.contrib.flatpages.views import flatpage
3 from django.core.exceptions import ValidationError
4 from django.core.validators import EmailValidator
5 from django.http.response import HttpResponseRedirect
6 from django.shortcuts import render_to_response
7 from django.template.context import RequestContext
8 from django.views.defaults import page_not_found
9 from django.views.generic import TemplateView
10 from pybb.views import ProfileEditView
11
12 from contact.models import Contact
13 from .forms import AvatarlessEditProfileForm
14
15
16 class HomeView(TemplateView):
17     template_name = "home.html"
18
19
20 def mil_home_view(request):
21     return flatpage(request, url='/' if request.LANGUAGE_CODE == 'pl' else '/en/')
22
23
24 def mil_404_view(request):
25     return page_not_found(request, '404_mil.html')
26
27
28 def mil_contact_view(request):
29     return flatpage(request, url='/kontakt_mil/' if request.LANGUAGE_CODE == 'pl' else '/contact_mil/')
30
31
32 def mil_knowledge_base_view(request, url):
33     return flatpage(request, url='bazawiedzy/' + url)
34
35
36 class AvatarlessProfileEditView(ProfileEditView):
37     form_class = AvatarlessEditProfileForm
38
39
40 def olimpiada_teaser(request):
41     if request.POST:
42         email = request.POST.get('email')
43         try:
44             EmailValidator()(email)
45             Contact.objects.create(
46                 contact=email,
47                 body={},
48                 ip=request.META['REMOTE_ADDR'],
49                 form_tag='olimpiada-teaser')
50         except ValidationError:
51             pass
52         return HttpResponseRedirect(request.path)
53     return render_to_response('olimpiada_teaser.html', context_instance=RequestContext(request))