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
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]
21 return render(request, 'main.html', {
24 'organizations': organizations,
25 'more_upcoming': more_upcoming,
26 'more_finished': more_finished,
27 'more_organizations': more_organizations,
30 def register(request):
31 if request.method == 'POST':
32 form = RegistrationForm(request.POST, request.FILES)
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']
40 u.set_password(form.cleaned_data['password'])
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.
49 MIL/PEER team.''', 'milpeer@mdrn.pl', [form.cleaned_data['email']])
52 form = RegistrationForm()
53 return render(request, 'registration.html', {'form': form})