Première version en Python-Django.
[auf_paf.git] / paf / views.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
9from django.template import Context, RequestContext
10from django.http import HttpResponseRedirect
11
12
13def register(request):
14 if request.method == 'POST':
15 form = RegistrationForm(request.POST)
16 if form.is_valid():
17 student = form.save()
18 return render_to_response('register_success.html', {'identifier': student.identifier}, context_instance = RequestContext(request))
19 else:
20 form = RegistrationForm()
21 c = {'registration_form': form}
22 c.update(csrf(request))
23 return render_to_response('register.html', c, context_instance = RequestContext(request))
24
25def login(request):
26 return HttpResponse('login')
27
28def edit_info(request):
29 user = request.user
30 student = Student.objects.get(identifier=user.username)
31 return StudentAdmin(Student, admin.site).change_view(request, str(student.id))
32
33def student_info(request, object_id=''):
34 return StudentAdmin(Student, admin.site).change_view(request, object_id)
35
36def student_list(request):
37 return StudentAdmin(Student, admin.site).changelist_view(request)
38
39def password_change(request):
40 return admin.site.password_change(request)
41
42def password_change_done(request):
43 return admin.site.password_change_done(request)
44
45def admin_home(request):
46 if request.user.is_superuser:
47 return admin.site.index(request)
3be30a94 48 return HttpResponseRedirect('/paf-v1/')
0ba28d89 49
50def change_student(request, id):
51 user = request.user
52 if user.is_superuser:
53 return StudentAdmin(Student, admin.site).change_view(request, id)
54 else:
3be30a94 55 return HttpResponse("Change student: user = " + user.username)