https fix
[redakcja.git] / redakcja / views.py
1 from django.shortcuts import render, redirect
2 from django.contrib.auth import authenticate, login
3 from django.contrib.auth.models import User
4 from django.core.mail import send_mail
5 from .forms import RegistrationForm
6 from catalogue.models import Document
7 from organizations.models import Organization
8
9 def main(request):
10     upcoming = Document.objects.filter(deleted=False).filter(publish_log=None)
11     finished = Document.objects.filter(deleted=False).exclude(publish_log=None)
12     organizations = Organization.objects.all()
13     more_upcoming = upcoming.count() > 8
14     more_finished = finished.count() > 8
15     more_organizations = organizations.count() > 8
16     upcoming = upcoming[:8]
17     finished = finished[:8]
18     organizations = organizations[:8]
19
20
21     return render(request, 'main.html', {
22         'finished': finished,
23         'upcoming': upcoming,
24         'organizations': organizations,
25         'more_upcoming': more_upcoming,
26         'more_finished': more_finished,
27         'more_organizations': more_organizations,
28     })
29
30 def register(request):
31     if request.method == 'POST':
32         form = RegistrationForm(request.POST, request.FILES)
33         if form.is_valid():
34             u = User.objects.create(
35                     username=form.cleaned_data['email'],
36                     first_name=form.cleaned_data['first_name'],
37                     last_name=form.cleaned_data['last_name'],
38                     email=form.cleaned_data['email']
39                 )
40             u.set_password(form.cleaned_data['password'])
41             u.save()
42             login(request, authenticate(username=form.cleaned_data['email'], password=form.cleaned_data['password']))
43             send_mail('Registered at MIL/PEER',
44 '''You have been successfully registered at MIL/PEER with this e-mail address.
45
46 Thank you.
47
48 -- 
49 MIL/PEER team.''', 'milpeer@mdrn.pl', [form.cleaned_data['email']])
50             return redirect('/')
51     else:
52         form = RegistrationForm()
53     return render(request, 'registration.html', {'form': form})