author | nishanth |
Thu, 01 Jul 2010 16:04:09 +0530 | |
changeset 77 | 7315ee25bf83 |
parent 76 | c84fc7ace0f5 |
child 78 | 2264a51fc9cf |
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 |
63
21cdadb1b98e
replaced the old form with new one in view and template for opening quiz
nishanth
parents:
48
diff
changeset
|
8 |
from offline.event.forms import EventCreateForm, OpenQuizForm |
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 |
|
44 | 10 |
from offline.quiz.models import Quiz, QuestionBank |
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 |
||
72 | 35 |
def event_admin(request): |
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 |
|
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
|
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 |
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
|
45 |
|
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
72
diff
changeset
|
46 |
def event_create(request): |
76 | 47 |
""" Create an event for which the quiz and feedback should be conducted. |
48 |
""" |
|
9 | 49 |
|
50 |
try: |
|
51 |
event = Event.objects.all()[0] |
|
52 |
return redirect("/event/admin/%s"%admin_key) |
|
53 |
except IndexError: |
|
54 |
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
|
55 |
|
9 | 56 |
if request.method == "POST": |
57 |
form = EventCreateForm(request.POST) |
|
58 |
if form.is_valid(): |
|
59 |
new_event.title = form.cleaned_data['title'] |
|
60 |
new_event.start_date = form.cleaned_data['start_date'] |
|
61 |
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
|
62 |
|
9 | 63 |
new_event.save() |
64 |
return redirect('/event/admin/%s'%ADMIN_KEY) |
|
65 |
else: |
|
66 |
return render_to_response('create_event.html',{'form':form}) |
|
67 |
else: |
|
68 |
form = EventCreateForm() |
|
69 |
return render_to_response('create_event.html',{'form':form}) |
|
23 | 70 |
|
74
46c5ae6594df
cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents:
73
diff
changeset
|
71 |
def open_quiz(request): |
25 | 72 |
""" check for admin and then for quiz status. |
73 |
""" |
|
74 |
||
75 |
try: |
|
76 |
event = Event.objects.all()[0] |
|
77 |
except IndexError: |
|
78 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
23 | 79 |
|
25 | 80 |
if event.quiz_status != "00": |
81 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
82 |
||
83 |
if request.method=="POST": |
|
65
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
84 |
form = OpenQuizForm(request.POST) |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
85 |
if form.is_valid(): |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
86 |
data = form.cleaned_data |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
87 |
quiz_num = data['quiz_num'] |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
88 |
topics = data['topics'] |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
89 |
|
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
90 |
for topic in topics: |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
91 |
QuestionBank.objects.filter(topic=topic).update(quiz_num=quiz_num) |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
92 |
|
25 | 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}) |
65
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
96 |
else: |
88a36f434284
added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents:
63
diff
changeset
|
97 |
return render_to_response("open_quiz.html", {"form":form}) |
25 | 98 |
else: |
63
21cdadb1b98e
replaced the old form with new one in view and template for opening quiz
nishanth
parents:
48
diff
changeset
|
99 |
form = OpenQuizForm() |
21cdadb1b98e
replaced the old form with new one in view and template for opening quiz
nishanth
parents:
48
diff
changeset
|
100 |
return render_to_response("open_quiz.html", {"form":form}) |
25 | 101 |
|
74
46c5ae6594df
cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents:
73
diff
changeset
|
102 |
def close_quiz(request): |
26 | 103 |
""" check for admin and then for quiz status. |
104 |
""" |
|
105 |
||
106 |
try: |
|
107 |
event = Event.objects.all()[0] |
|
108 |
except IndexError: |
|
109 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
110 |
||
111 |
if event.quiz_status == "00": |
|
112 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
113 |
||
38 | 114 |
quiz_num = event.quiz_status |
115 |
||
26 | 116 |
event.quiz_status = "00" |
117 |
event.save() |
|
118 |
||
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
|
38 | 123 |
return render_to_response("close_quiz.html", {"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num]}) |
124 |
||
75 | 125 |
def list_toppers(request, quiz_num): |
41 | 126 |
""" check for admin key |
127 |
Then check for quiz_num in ['11', ..] |
|
128 |
then give appropriate response. |
|
129 |
""" |
|
130 |
||
131 |
try: |
|
132 |
event = Event.objects.all()[0] |
|
133 |
except IndexError: |
|
134 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
135 |
||
136 |
if quiz_num not in ["11", "12", "21"]: |
|
137 |
raise Http404 |
|
138 |
||
139 |
quizzes = Quiz.objects.filter(event=event,quiz_num=quiz_num) |
|
140 |
quizzes_with_scores = quizzes.annotate(score=Sum('que_answered__is_correct')) |
|
141 |
sorted_quizzes = quizzes_with_scores.order_by("score").reverse() |
|
142 |
||
42
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
143 |
return render_to_response("list_toppers.html", {"sorted_quizzes":sorted_quizzes,"admin_key":ADMIN_KEY, "event":event, "quiz_name":num2name[quiz_num]}) |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
144 |
|
75 | 145 |
def user_dump(request, quiz_key, user_name): |
42
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
146 |
""" check for admin_key |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
147 |
then get quiz by quiz_key and user_name. |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
148 |
then display the dump |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
149 |
""" |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
150 |
|
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
151 |
try: |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
152 |
event = Event.objects.all()[0] |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
153 |
except IndexError: |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
154 |
return redirect('/event/create/%s'%ADMIN_KEY) |
44 | 155 |
|
42
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
156 |
try: |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
157 |
quiz = Quiz.objects.get(event=event, key=quiz_key) |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
158 |
except Quiz.DoesNotExist: |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
159 |
raise Http404 |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
160 |
|
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
161 |
if not quiz.user.username == user_name: |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
162 |
raise Http404 |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
163 |
|
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
164 |
quiz_name = num2name[quiz.quiz_num] |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
165 |
if request.method == "POST": |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
166 |
for ans in quiz.que_answered.all(): |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
167 |
ans.is_correct = True if str(ans.question.id) in request.POST else False |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
168 |
ans.save() |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
169 |
return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz.quiz_num)) |
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
170 |
else: |
44 | 171 |
return render_to_response("user_dump.html", {"quiz":quiz, "quiz_name":quiz_name, "admin_key":ADMIN_KEY}) |
172 |
||
75 | 173 |
def que_dump(request, que_id): |
44 | 174 |
""" check for admin key |
175 |
then simply render all answers corresponding to the question. |
|
176 |
""" |
|
177 |
||
178 |
try: |
|
179 |
event = Event.objects.all()[0] |
|
180 |
except IndexError: |
|
181 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
42
007d87112911
created a user_dump page that shows all the answers entered by user at one place
nishanth
parents:
41
diff
changeset
|
182 |
|
44 | 183 |
try: |
184 |
question = QuestionBank.objects.get(id=que_id) |
|
185 |
except QuestionBank.DoesNotExist: |
|
186 |
raise Http404 |
|
187 |
||
188 |
quiz_num = question.quiz_num |
|
189 |
quiz_name = num2name[quiz_num] |
|
190 |
||
191 |
answers = question.answer.all() |
|
192 |
||
193 |
if request.method == "POST": |
|
194 |
for ans in answers: |
|
195 |
ans.is_correct = True if str(ans.id) in request.POST else False |
|
196 |
ans.save() |
|
197 |
return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz_num)) |
|
198 |
else: |
|
48
aae2f69ba89c
updated the que_dump template to show the question properly.
nishanth
parents:
44
diff
changeset
|
199 |
return render_to_response("que_dump.html", {"quiz_name":quiz_name, "question":question, "answers":answers}) |