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