author | nishanth |
Wed, 21 Apr 2010 21:53:33 +0530 | |
changeset 39 | 0fa055b8ea98 |
parent 38 | 307c6887cc67 |
child 41 | d424b9668a74 |
permissions | -rw-r--r-- |
6 | 1 |
from django.http import Http404 |
9 | 2 |
from django.shortcuts import render_to_response, redirect |
6 | 3 |
|
39
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
4 |
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
|
5 |
|
6 | 6 |
from offline.event.models import Event |
9 | 7 |
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
|
8 |
|
0fa055b8ea98
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents:
38
diff
changeset
|
9 |
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
|
10 |
|
34
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
11 |
num2name = {"11" : "Day 1 Quiz 1", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
12 |
"12" : "Day 1 Quiz 2", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
13 |
"21" : "Day 2 Quiz 1", |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
14 |
} |
8d0d82c981b3
added "return to admin page" link in open_quiz page
nishanth
parents:
26
diff
changeset
|
15 |
|
6 | 16 |
def event_home(request): |
17 |
""" The page for people to view. |
|
18 |
""" |
|
19 |
||
20 |
try: |
|
21 |
event = Event.objects.all()[0] |
|
22 |
except IndexError: |
|
23 |
raise Http404 |
|
24 |
||
25 |
ip = request.META['REMOTE_ADDR'] |
|
26 |
||
27 |
can_submit_feedback = True if event.feedback_status != '0' and \ |
|
28 |
not event.feedback.filter(day=event.feedback_status,user_ip=ip) else False |
|
23 | 29 |
can_take_quiz = True if event.quiz_status != "00" else False |
6 | 30 |
|
31 |
return render_to_response('home.html', {'event':event, 'can_submit_feedback':can_submit_feedback, 'can_take_quiz':can_take_quiz}) |
|
32 |
||
9 | 33 |
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
|
34 |
""" 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
|
35 |
""" |
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 |
|
9 | 37 |
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
|
38 |
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
|
39 |
|
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 |
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
|
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 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
|
46 |
|
9 | 47 |
def event_create(request, admin_key): |
48 |
||
49 |
if not admin_key == ADMIN_KEY: |
|
50 |
raise Http404 |
|
51 |
||
52 |
try: |
|
53 |
event = Event.objects.all()[0] |
|
54 |
return redirect("/event/admin/%s"%admin_key) |
|
55 |
except IndexError: |
|
56 |
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
|
57 |
|
9 | 58 |
if request.method == "POST": |
59 |
form = EventCreateForm(request.POST) |
|
60 |
if form.is_valid(): |
|
61 |
new_event.title = form.cleaned_data['title'] |
|
62 |
new_event.start_date = form.cleaned_data['start_date'] |
|
63 |
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
|
64 |
|
9 | 65 |
new_event.save() |
66 |
return redirect('/event/admin/%s'%ADMIN_KEY) |
|
67 |
else: |
|
68 |
return render_to_response('create_event.html',{'form':form}) |
|
69 |
else: |
|
70 |
form = EventCreateForm() |
|
71 |
return render_to_response('create_event.html',{'form':form}) |
|
23 | 72 |
|
73 |
def open_quiz(request, admin_key): |
|
25 | 74 |
""" check for admin and then for quiz status. |
75 |
""" |
|
76 |
||
77 |
if not admin_key == ADMIN_KEY: |
|
78 |
raise Http404 |
|
79 |
||
80 |
try: |
|
81 |
event = Event.objects.all()[0] |
|
82 |
except IndexError: |
|
83 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
23 | 84 |
|
25 | 85 |
if event.quiz_status != "00": |
86 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
87 |
||
88 |
if request.method=="POST": |
|
89 |
try: |
|
90 |
quiz_num = request.POST['quiz_num'] |
|
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}) |
25 | 94 |
except MultiValueDictKeyError: |
95 |
raise Http404 |
|
96 |
else: |
|
97 |
return render_to_response("open_quiz.html") |
|
98 |
||
26 | 99 |
def close_quiz(request, admin_key): |
100 |
""" check for admin and then for quiz status. |
|
101 |
""" |
|
102 |
||
103 |
if not admin_key == ADMIN_KEY: |
|
104 |
raise Http404 |
|
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 |