author | nishanth |
Thu, 22 Apr 2010 00:36:08 +0530 | |
changeset 41 | d424b9668a74 |
parent 39 | 0fa055b8ea98 |
child 42 | 007d87112911 |
permissions | -rw-r--r-- |
41 | 1 |
from django.db.models import Sum |
6 | 2 |
from django.http import Http404 |
9 | 3 |
from django.shortcuts import render_to_response, redirect |
6 | 4 |
|
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
5 |
from offline.settings import ADMIN_KEY |
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
6 |
|
6 | 7 |
from offline.event.models import Event |
9 | 8 |
from offline.event.forms import EventCreateForm |
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
9 |
|
41 | 10 |
from offline.quiz.models import Quiz |
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
11 |
from offline.quiz.utils import correct_quiz |
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
12 |
|
34
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
13 |
num2name = {"11" : "Day 1 Quiz 1", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
14 |
"12" : "Day 1 Quiz 2", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
15 |
"21" : "Day 2 Quiz 1", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
16 |
} |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
17 |
|
6 | 18 |
def event_home(request): |
19 |
""" The page for people to view. |
|
20 |
""" |
|
21 |
||
22 |
try: |
|
23 |
event = Event.objects.all()[0] |
|
24 |
except IndexError: |
|
25 |
raise Http404 |
|
26 |
||
27 |
ip = request.META['REMOTE_ADDR'] |
|
28 |
||
29 |
can_submit_feedback = True if event.feedback_status != '0' and \ |
|
30 |
not event.feedback.filter(day=event.feedback_status,user_ip=ip) else False |
|
23 | 31 |
can_take_quiz = True if event.quiz_status != "00" else False |
6 | 32 |
|
33 |
return render_to_response('home.html', {'event':event, 'can_submit_feedback':can_submit_feedback, 'can_take_quiz':can_take_quiz}) |
|
34 |
||
9 | 35 |
def event_admin(request, admin_key): |
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
36 |
""" see if the key is correct and then display options. |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
37 |
""" |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
38 |
|
9 | 39 |
if not admin_key == ADMIN_KEY: |
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
40 |
raise Http404 |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
41 |
|
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
42 |
try: |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
43 |
event = Event.objects.all()[0] |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
44 |
except IndexError: |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
45 |
return redirect('/event/create/%s'%ADMIN_KEY) |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
46 |
|
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
47 |
return render_to_response('admin.html', {'event':event, 'admin_key':ADMIN_KEY}) |
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
48 |
|
9 | 49 |
def event_create(request, admin_key): |
50 |
||
51 |
if not admin_key == ADMIN_KEY: |
|
52 |
raise Http404 |
|
53 |
||
54 |
try: |
|
55 |
event = Event.objects.all()[0] |
|
56 |
return redirect("/event/admin/%s"%admin_key) |
|
57 |
except IndexError: |
|
58 |
new_event = Event() |
|
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
59 |
|
9 | 60 |
if request.method == "POST": |
61 |
form = EventCreateForm(request.POST) |
|
62 |
if form.is_valid(): |
|
63 |
new_event.title = form.cleaned_data['title'] |
|
64 |
new_event.start_date = form.cleaned_data['start_date'] |
|
65 |
new_event.stop_date = form.cleaned_data['stop_date'] |
|
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
6
diff
changeset
|
66 |
|
9 | 67 |
new_event.save() |
68 |
return redirect('/event/admin/%s'%ADMIN_KEY) |
|
69 |
else: |
|
70 |
return render_to_response('create_event.html',{'form':form}) |
|
71 |
else: |
|
72 |
form = EventCreateForm() |
|
73 |
return render_to_response('create_event.html',{'form':form}) |
|
23 | 74 |
|
75 |
def open_quiz(request, admin_key): |
|
25 | 76 |
""" check for admin and then for quiz status. |
77 |
""" |
|
78 |
||
79 |
if not admin_key == ADMIN_KEY: |
|
80 |
raise Http404 |
|
81 |
||
82 |
try: |
|
83 |
event = Event.objects.all()[0] |
|
84 |
except IndexError: |
|
85 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
23 | 86 |
|
25 | 87 |
if event.quiz_status != "00": |
88 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
89 |
||
90 |
if request.method=="POST": |
|
91 |
try: |
|
92 |
quiz_num = request.POST['quiz_num'] |
|
93 |
event.quiz_status = quiz_num |
|
94 |
event.save() |
|
34
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
95 |
return render_to_response("open_quiz.html",{"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num], 'success':True}) |
25 | 96 |
except MultiValueDictKeyError: |
97 |
raise Http404 |
|
98 |
else: |
|
99 |
return render_to_response("open_quiz.html") |
|
100 |
||
26 | 101 |
def close_quiz(request, admin_key): |
102 |
""" check for admin and then for quiz status. |
|
103 |
""" |
|
104 |
||
105 |
if not admin_key == ADMIN_KEY: |
|
106 |
raise Http404 |
|
107 |
||
108 |
try: |
|
109 |
event = Event.objects.all()[0] |
|
110 |
except IndexError: |
|
111 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
112 |
||
113 |
if event.quiz_status == "00": |
|
114 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
115 |
||
38 | 116 |
quiz_num = event.quiz_status |
117 |
||
26 | 118 |
event.quiz_status = "00" |
119 |
event.save() |
|
120 |
||
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
121 |
event_quizzes = event.quiz.filter(quiz_num=quiz_num) |
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
122 |
for quiz in event_quizzes: |
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
123 |
correct_quiz(quiz) |
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
124 |
|
38 | 125 |
return render_to_response("close_quiz.html", {"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num]}) |
126 |
||
41 | 127 |
def list_toppers(request, admin_key, quiz_num): |
128 |
""" check for admin key |
|
129 |
Then check for quiz_num in ['11', ..] |
|
130 |
then give appropriate response. |
|
131 |
""" |
|
132 |
||
133 |
if not admin_key == ADMIN_KEY: |
|
134 |
raise Http404 |
|
135 |
||
136 |
try: |
|
137 |
event = Event.objects.all()[0] |
|
138 |
except IndexError: |
|
139 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
140 |
||
141 |
if quiz_num not in ["11", "12", "21"]: |
|
142 |
raise Http404 |
|
143 |
||
144 |
quizzes = Quiz.objects.filter(event=event,quiz_num=quiz_num) |
|
145 |
quizzes_with_scores = quizzes.annotate(score=Sum('que_answered__is_correct')) |
|
146 |
sorted_quizzes = quizzes_with_scores.order_by("score").reverse() |
|
147 |
||
148 |
return render_to_response("list_toppers.html", {"sorted_quizzes":sorted_quizzes, "event":event, "quiz_name":num2name[quiz_num]}) |
|
149 |