author | nishanth |
Tue, 20 Apr 2010 23:55:04 +0530 | |
changeset 25 | 4143a8f90b00 |
parent 23 | f57c30096b51 |
child 26 | 10760aa2cf52 |
permissions | -rw-r--r-- |
6 | 1 |
from django.http import Http404 |
9 | 2 |
from django.shortcuts import render_to_response, redirect |
6 | 3 |
|
4 |
from offline.event.models import Event |
|
9 | 5 |
from offline.event.forms import EventCreateForm |
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
|
6 |
from offline.settings import 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
|
7 |
|
6 | 8 |
def event_home(request): |
9 |
""" The page for people to view. |
|
10 |
""" |
|
11 |
||
12 |
try: |
|
13 |
event = Event.objects.all()[0] |
|
14 |
except IndexError: |
|
15 |
raise Http404 |
|
16 |
||
17 |
ip = request.META['REMOTE_ADDR'] |
|
18 |
||
19 |
can_submit_feedback = True if event.feedback_status != '0' and \ |
|
20 |
not event.feedback.filter(day=event.feedback_status,user_ip=ip) else False |
|
23 | 21 |
can_take_quiz = True if event.quiz_status != "00" else False |
6 | 22 |
|
23 |
return render_to_response('home.html', {'event':event, 'can_submit_feedback':can_submit_feedback, 'can_take_quiz':can_take_quiz}) |
|
24 |
||
9 | 25 |
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
|
26 |
""" 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
|
27 |
""" |
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
|
28 |
|
9 | 29 |
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
|
30 |
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
|
31 |
|
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
|
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 |
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
|
38 |
|
9 | 39 |
def event_create(request, admin_key): |
40 |
||
41 |
if not admin_key == ADMIN_KEY: |
|
42 |
raise Http404 |
|
43 |
||
44 |
try: |
|
45 |
event = Event.objects.all()[0] |
|
46 |
return redirect("/event/admin/%s"%admin_key) |
|
47 |
except IndexError: |
|
48 |
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
|
49 |
|
9 | 50 |
if request.method == "POST": |
51 |
form = EventCreateForm(request.POST) |
|
52 |
if form.is_valid(): |
|
53 |
new_event.title = form.cleaned_data['title'] |
|
54 |
new_event.start_date = form.cleaned_data['start_date'] |
|
55 |
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
|
56 |
|
9 | 57 |
new_event.save() |
58 |
return redirect('/event/admin/%s'%ADMIN_KEY) |
|
59 |
else: |
|
60 |
return render_to_response('create_event.html',{'form':form}) |
|
61 |
else: |
|
62 |
form = EventCreateForm() |
|
63 |
return render_to_response('create_event.html',{'form':form}) |
|
23 | 64 |
|
65 |
def open_quiz(request, admin_key): |
|
25 | 66 |
""" check for admin and then for quiz status. |
67 |
""" |
|
68 |
||
69 |
if not admin_key == ADMIN_KEY: |
|
70 |
raise Http404 |
|
71 |
||
72 |
try: |
|
73 |
event = Event.objects.all()[0] |
|
74 |
except IndexError: |
|
75 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
23 | 76 |
|
25 | 77 |
if event.quiz_status != "00": |
78 |
return redirect('/event/create/%s'%ADMIN_KEY) |
|
79 |
||
80 |
if request.method=="POST": |
|
81 |
try: |
|
82 |
quiz_num = request.POST['quiz_num'] |
|
83 |
event.quiz_status = quiz_num |
|
84 |
event.save() |
|
85 |
return render_to_response("open_quiz.html",{'success':True}) |
|
86 |
except MultiValueDictKeyError: |
|
87 |
raise Http404 |
|
88 |
else: |
|
89 |
return render_to_response("open_quiz.html") |
|
90 |