equal
deleted
inserted
replaced
1 from django.db import IntegrityError |
1 from django.db import IntegrityError |
|
2 |
|
3 from django.http import Http404 |
2 |
4 |
3 from django.contrib.auth.models import User |
5 from django.contrib.auth.models import User |
4 from django.contrib.auth import login, logout, authenticate |
6 from django.contrib.auth import login, logout, authenticate |
5 |
7 |
6 from django.shortcuts import redirect, render_to_response |
8 from django.shortcuts import redirect, render_to_response |
|
9 |
|
10 from offline.event.models import Event |
7 |
11 |
8 from offline.quiz.utils import gen_key |
12 from offline.quiz.utils import gen_key |
9 from offline.quiz.models import Profile |
13 from offline.quiz.models import Profile |
10 |
14 |
11 from offline.quiz.forms import UserRegisterForm |
15 from offline.quiz.forms import UserRegisterForm |
14 """ first see if user is authenticated. |
18 """ first see if user is authenticated. |
15 If he is, redirect to the page where quiz happens. |
19 If he is, redirect to the page where quiz happens. |
16 Else register the user |
20 Else register the user |
17 """ |
21 """ |
18 |
22 |
|
23 try: |
|
24 event = Event.objects.all()[0] |
|
25 except IndexError: |
|
26 raise Http404 |
|
27 |
|
28 if event.quiz_status == '00': |
|
29 raise Http404 |
|
30 |
19 user = request.user |
31 user = request.user |
20 if user.is_authenticated(): |
32 if user.is_authenticated(): |
21 return redirect("/quiz/start/%s"%user.username) |
33 return redirect("/quiz/start/%s"%user.username) |
22 |
34 |
23 try: |
35 try: |
24 Quiz.objects.get(user_ip=ip) |
36 Quiz.objects.get(event=event,user_ip=ip,quiz_num=event.quiz_status) |
25 return redirect("/quiz/complete") |
37 return redirect("/quiz/complete") |
26 except Quiz.DoesNotExist: |
38 except Quiz.DoesNotExist: |
27 pass |
39 pass |
28 |
40 |
29 if request.method == "POST": |
41 if request.method == "POST": |