author | nishanth |
Thu, 22 Apr 2010 01:41:43 +0530 | |
changeset 43 | 265ed367e8cc |
parent 37 | 1141580fb82f |
child 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 |
||
8 | 57 |
def open_feedback(request, admin_key): |
58 |
""" |
|
59 |
Check for key and then exiatance of event. |
|
60 |
""" |
|
61 |
||
62 |
if not admin_key == ADMIN_KEY: |
|
63 |
raise Http404 |
|
64 |
||
65 |
try: |
|
66 |
event = Event.objects.all()[0] |
|
67 |
except IndexError: |
|
68 |
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
|
69 |
|
8 | 70 |
if event.feedback_status == '0': |
71 |
no_of_days = (event.stop_date - event.start_date).days + 1 |
|
72 |
if request.method == "POST": |
|
73 |
day = request.POST['day'] |
|
74 |
event.feedback_status = day |
|
75 |
event.save() |
|
36
9e0d6aecf269
added "return to admin page" link in open_feedback page
nishanth
parents:
11
diff
changeset
|
76 |
return render_to_response('open_feedback.html', {'success': True, 'day':day, 'event':event, "admin_key":ADMIN_KEY}) |
8 | 77 |
else: |
78 |
return render_to_response('open_feedback.html', {'event': event, 'days': range(1,no_of_days+1)}) |
|
79 |
else: |
|
80 |
day = event.feedback_status |
|
81 |
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
|
82 |
|
8 | 83 |
def close_feedback(request, admin_key): |
84 |
""" |
|
85 |
simply set feedback status to 0 |
|
86 |
""" |
|
87 |
||
88 |
if not admin_key == ADMIN_KEY: |
|
89 |
raise Http404 |
|
90 |
||
91 |
try: |
|
92 |
event = Event.objects.all()[0] |
|
93 |
except IndexError: |
|
94 |
raise Http404 |
|
95 |
||
96 |
day = event.feedback_status |
|
97 |
event.feedback_status = '0' |
|
98 |
event.save() |
|
37
1141580fb82f
added "return to admin page" link in close_feedback page
nishanth
parents:
36
diff
changeset
|
99 |
return render_to_response('close_feedback.html', {'event': event, 'day':day, "admin_key":ADMIN_KEY}) |
8 | 100 |
|
10 | 101 |
def list_feedbacks(request, admin_key): |
102 |
""" print a list of all the feedbacks collected. |
|
103 |
""" |
|
104 |
||
105 |
if not admin_key == ADMIN_KEY: |
|
106 |
raise Http404 |
|
107 |
||
108 |
try: |
|
109 |
event = Event.objects.all()[0] |
|
110 |
except IndexError: |
|
111 |
raise Http404 |
|
112 |
||
113 |
||
114 |
no_of_days = (event.stop_date - event.start_date).days |
|
115 |
days = range(1,no_of_days+2) |
|
116 |
||
117 |
feeds_list = [] |
|
118 |
for day in days: |
|
119 |
day_feeds = Feedback.objects.filter(event=event,day=day) |
|
120 |
if day_feeds.count(): |
|
121 |
day_list = [] |
|
122 |
for feed in day_feeds: |
|
123 |
day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace, |
|
124 |
feed.applicability, feed.problems, feed.exercises, feed.comments))) |
|
125 |
feeds_list.extend(["Day %s"%day, day_list]) |
|
126 |
||
127 |
return render_to_response('list_feedbacks.html',{'event':event, 'feeds_list':feeds_list}) |
|
128 |
||
11 | 129 |
def view_report(request, admin_key): |
130 |
""" compile the report and display it. |
|
131 |
""" |
|
132 |
||
133 |
if not admin_key == ADMIN_KEY: |
|
134 |
raise Http404 |
|
135 |
||
136 |
try: |
|
137 |
event = Event.objects.all()[0] |
|
138 |
except IndexError: |
|
139 |
raise Http404 |
|
140 |
||
141 |
no_of_days = (event.stop_date - event.start_date).days |
|
142 |
days = range(1,no_of_days+2) |
|
143 |
||
144 |
workshop_report = [] |
|
145 |
||
146 |
for day in days: |
|
147 |
day_num = str(day) |
|
148 |
day_feeds = event.feedback.filter(day=day_num) |
|
149 |
||
150 |
day_report = make_day_report(day_feeds) |
|
151 |
if day_report: |
|
152 |
day_comments = [ feed.comments for feed in day_feeds if feed.comments ] |
|
153 |
day_report.extend(["General comments:",day_comments]) |
|
154 |
workshop_report.extend( [ "Day %s"%day_num, day_report] ) |
|
155 |
||
156 |
return render_to_response("show_report.html", {"event":event, "workshop_report":workshop_report}) |