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