Nettoyage, 1ère passe…
[auf_paf.git] / paf / views 2.py
CommitLineData
0ba28d89 1from django.shortcuts import render_to_response
2from paf.forms import RegistrationForm
3from django.core.context_processors import csrf
4from django.http import HttpResponse
5from paf.admin import StudentAdmin
6from paf.models import Student
7from django.contrib import admin
8from django.contrib.auth.models import User, Group
9
10def register(request):
11 if request.method == 'POST':
12 form = RegistrationForm(request.POST)
13 if form.is_valid():
14 cd = form.cleaned_data
15 if User.objects.filter(username=cd['username']):
16 #return HttpResponse("Username already exists")
17 c = {'registration_form': form, 'user_exist': True}
18 c.update(csrf(request))
19 return render_to_response('register.html', c)
20 else:
21 user = User(username=cd['username'], first_name=cd['firstname'], last_name=cd['lastname'])
22 user.set_password(cd['password'])
23 user.save()
24 group = Group.objects.get(name='student')
25 user.groups = [group]
26 user.save()
27 return HttpResponse("<a href='/paf/login/'>Login</a>")
28 else:
29 form = RegistrationForm()
30 c = {'registration_form': form}
31 c.update(csrf(request))
32 return render_to_response('register.html', c)
33
34def login(request):
35 return HttpResponse('login')
36
37def change_student(request, id):
38 user = request.user
39 if user.is_superuser:
40 return StudentAdmin(Student, admin.site).change_view(request, id)
41 else:
42 return HttpResponse("Change student: user = " + user.username)