author | nishanth |
Thu, 01 Jul 2010 16:01:48 +0530 | |
changeset 78 | 2264a51fc9cf |
parent 73 | 5c2c74afb94e |
permissions | -rw-r--r-- |
5 | 1 |
from django.shortcuts import render_to_response |
2 |
from django.http import Http404 |
|
3 |
||
8 | 4 |
from offline.settings import ADMIN_KEY |
5 |
||
5 | 6 |
from offline.event.models import Event |
7 |
||
8 |
from offline.feedback.models import Feedback |
|
9 |
from offline.feedback.forms import FeedbackForm |
|
11 | 10 |
from offline.feedback.utils import make_day_report |
5 | 11 |
|
12 |
def submit_feedback(request): |
|
13 |
||
14 |
""" see if the ip address has already submitted a feedback. |
|
15 |
if not, collect the feedback. |
|
16 |
""" |
|
17 |
||
18 |
try: |
|
19 |
event = Event.objects.all()[0] |
|
20 |
except IndexError: |
|
21 |
raise Http404 |
|
22 |
||
23 |
if event.feedback_status == "0": |
|
24 |
raise Http404 |
|
25 |
else: |
|
26 |
day = event.feedback_status |
|
27 |
||
28 |
ip = request.META['REMOTE_ADDR'] |
|
29 |
||
30 |
try: |
|
31 |
Feedback.objects.get(event=event,day=day,user_ip=ip) |
|
32 |
return render_to_response('submit_feedback.html', {'submitted':True, 'event':event}) |
|
33 |
except Feedback.DoesNotExist: |
|
34 |
new_feedback = Feedback(event=event,day=day,user_ip=ip) |
|
35 |
||
36 |
if request.method == "POST": |
|
37 |
form = FeedbackForm(request.POST) |
|
38 |
if form.is_valid(): |
|
39 |
data = form.cleaned_data |
|
40 |
new_feedback.topics = data['topics'] |
|
41 |
new_feedback.depth = data['depth'] |
|
42 |
new_feedback.methodology = data['methodology'] |
|
43 |
new_feedback.pace = data['pace'] |
|
44 |
new_feedback.applicability = data['applicability'] |
|
45 |
new_feedback.problems = data['problems'] |
|
46 |
new_feedback.exercises = data['exercises'] |
|
47 |
new_feedback.comments = data['comments'] |
|
48 |
new_feedback.save() |
|
49 |
||
50 |
return render_to_response('submit_feedback.html', {'submitted':True, 'event':event}) |
|
51 |
else: |
|
52 |
return render_to_response('submit_feedback.html',{ 'form':form, 'event':event}) |
|
53 |
else: |
|
54 |
form = FeedbackForm() |
|
55 |
return render_to_response('submit_feedback.html',{'form':form, 'event':event}) |
|
56 |
||
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
57 |
def open_feedback(request): |
8 | 58 |
""" |
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
59 |
Check for the existance of event. |
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
60 |
""" |
8 | 61 |
|
62 |
try: |
|
63 |
event = Event.objects.all()[0] |
|
64 |
except IndexError: |
|
65 |
raise Http404 |
|
7
dfedb369f32e
first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents:
5
diff
changeset
|
66 |
|
8 | 67 |
if event.feedback_status == '0': |
68 |
no_of_days = (event.stop_date - event.start_date).days + 1 |
|
69 |
if request.method == "POST": |
|
70 |
day = request.POST['day'] |
|
71 |
event.feedback_status = day |
|
72 |
event.save() |
|
36
9e0d6aecf269
added "return to admin page" link in open_feedback page
nishanth
parents:
11
diff
changeset
|
73 |
return render_to_response('open_feedback.html', {'success': True, 'day':day, 'event':event, "admin_key":ADMIN_KEY}) |
8 | 74 |
else: |
75 |
return render_to_response('open_feedback.html', {'event': event, 'days': range(1,no_of_days+1)}) |
|
76 |
else: |
|
77 |
day = event.feedback_status |
|
78 |
return render_to_response('open_feedback.html', {'success': True, 'day':day, '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:
5
diff
changeset
|
79 |
|
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
80 |
def close_feedback(request): |
8 | 81 |
""" |
82 |
simply set feedback status to 0 |
|
83 |
""" |
|
84 |
||
85 |
try: |
|
86 |
event = Event.objects.all()[0] |
|
87 |
except IndexError: |
|
88 |
raise Http404 |
|
89 |
||
90 |
day = event.feedback_status |
|
91 |
event.feedback_status = '0' |
|
92 |
event.save() |
|
37
1141580fb82f
added "return to admin page" link in close_feedback page
nishanth
parents:
36
diff
changeset
|
93 |
return render_to_response('close_feedback.html', {'event': event, 'day':day, "admin_key":ADMIN_KEY}) |
8 | 94 |
|
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
95 |
def list_feedbacks(request): |
10 | 96 |
""" print a list of all the feedbacks collected. |
97 |
""" |
|
98 |
||
99 |
try: |
|
100 |
event = Event.objects.all()[0] |
|
101 |
except IndexError: |
|
102 |
raise Http404 |
|
103 |
||
104 |
||
105 |
no_of_days = (event.stop_date - event.start_date).days |
|
106 |
days = range(1,no_of_days+2) |
|
107 |
||
108 |
feeds_list = [] |
|
109 |
for day in days: |
|
110 |
day_feeds = Feedback.objects.filter(event=event,day=day) |
|
111 |
if day_feeds.count(): |
|
112 |
day_list = [] |
|
113 |
for feed in day_feeds: |
|
114 |
day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace, |
|
115 |
feed.applicability, feed.problems, feed.exercises, feed.comments))) |
|
116 |
feeds_list.extend(["Day %s"%day, day_list]) |
|
117 |
||
118 |
return render_to_response('list_feedbacks.html',{'event':event, 'feeds_list':feeds_list}) |
|
119 |
||
73
5c2c74afb94e
checking for admin key is done via urls in all the views related to feedback
nishanth
parents:
37
diff
changeset
|
120 |
def view_report(request): |
11 | 121 |
""" compile the report and display it. |
122 |
""" |
|
123 |
||
124 |
try: |
|
125 |
event = Event.objects.all()[0] |
|
126 |
except IndexError: |
|
127 |
raise Http404 |
|
128 |
||
129 |
no_of_days = (event.stop_date - event.start_date).days |
|
130 |
days = range(1,no_of_days+2) |
|
131 |
||
132 |
workshop_report = [] |
|
133 |
||
134 |
for day in days: |
|
135 |
day_num = str(day) |
|
136 |
day_feeds = event.feedback.filter(day=day_num) |
|
137 |
||
138 |
day_report = make_day_report(day_feeds) |
|
139 |
if day_report: |
|
140 |
day_comments = [ feed.comments for feed in day_feeds if feed.comments ] |
|
141 |
day_report.extend(["General comments:",day_comments]) |
|
142 |
workshop_report.extend( [ "Day %s"%day_num, day_report] ) |
|
143 |
||
144 |
return render_to_response("show_report.html", {"event":event, "workshop_report":workshop_report}) |