0d1c841c74576484a2194f1268f0b5b7b55997eb
[auf_paf.git] / paf / views.py
1 from django.shortcuts import render_to_response
2 from paf.forms import RegistrationForm
3 from django.core.context_processors import csrf
4 from django.http import HttpResponse
5 from paf.admin import StudentAdmin
6 from paf.models import Student
7 from django.contrib import admin
8 from django.contrib.auth.models import User, Group
9 from django.template import Context, RequestContext
10 from django.http import HttpResponseRedirect
11
12
13 def 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
25 def login(request):
26 return HttpResponse('login')
27
28 def 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
33 def student_info(request, object_id=''):
34 return StudentAdmin(Student, admin.site).change_view(request, object_id)
35
36 def student_list(request):
37 return StudentAdmin(Student, admin.site).changelist_view(request)
38
39 def password_change(request):
40 return admin.site.password_change(request)
41
42 def password_change_done(request):
43 return admin.site.password_change_done(request)
44
45 def admin_home(request):
46 if request.user.is_superuser:
47 return admin.site.index(request)
48 return HttpResponseRedirect('/')
49
50 def 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:
55 return HttpResponse("Change student: user = " + user.username)