author | nishanth |
Thu, 15 Apr 2010 12:36:21 +0530 | |
changeset 39 | 61d558a69b0d |
parent 38 | b63b78017225 |
child 41 | ab0a8a72b069 |
permissions | -rw-r--r-- |
5 | 1 |
from django.shortcuts import render_to_response, redirect |
2 |
||
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
3 |
from workshop.reg.models import Event |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
4 |
|
5 | 5 |
from workshop.feedback.models import Feedback |
6 |
from workshop.feedback.forms import FeedbackForm |
|
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
7 |
from workshop.feedback.utils import compile_report |
5 | 8 |
|
9 |
from django.http import HttpResponse |
|
10 |
||
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
5
diff
changeset
|
11 |
def submit_feedback(request, event_key): |
5 | 12 |
""" see if the ip address has already submitted a feedback. |
13 |
if not, collect the feedback. |
|
14 |
""" |
|
15 |
||
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
16 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
17 |
event = Event.objects.get(key=event_key) |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
18 |
except Event.DoesNotExist: |
35 | 19 |
raise Http404 |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
20 |
|
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
21 |
if event.feedback_status == "0": |
35 | 22 |
raise Http404 |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
23 |
|
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
24 |
user_ip = request.META["REMOTE_ADDR"] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
25 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
26 |
old_feedback = Feedback.objects.get(day=event.feedback_status, user_ip=user_ip) |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
27 |
return render_to_response('feedback.html', {'submitted':True}) |
35 | 28 |
except Feedback.DoesNotExist: |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
29 |
new_feedback = Feedback(event=event, user_ip=user_ip, day=event.feedback_status) |
5 | 30 |
|
31 |
if request.method == "POST": |
|
32 |
form = FeedbackForm(request.POST) |
|
33 |
if form.is_valid(): |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
34 |
data = form.cleaned_data |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
35 |
new_feedback.topics = data['topics'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
36 |
new_feedback.depth = data['depth'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
37 |
new_feedback.methodology = data['methodology'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
38 |
new_feedback.pace = data['pace'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
39 |
new_feedback.applicability = data['applicability'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
40 |
new_feedback.problems = data['problems'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
41 |
new_feedback.exercises = data['exercises'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
42 |
new_feedback.comments = data['comments'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
43 |
new_feedback.save() |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
44 |
return render_to_response('feedback.html', {'submitted':True}) |
5 | 45 |
else: |
46 |
return render_to_response('feedback.html',{'form':form}) |
|
47 |
else: |
|
48 |
form = FeedbackForm() |
|
49 |
return render_to_response('feedback.html',{'form':form}) |
|
50 |
||
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
5
diff
changeset
|
51 |
def list_feedbacks(request, event_key): |
5 | 52 |
""" print a list of all the feedbacks collected. |
53 |
""" |
|
54 |
||
36 | 55 |
user = request.user |
56 |
||
57 |
try: |
|
58 |
event = Event.objects.get(key__iexact=event_key) |
|
59 |
except Event.DoesNotExist: |
|
60 |
raise Http404 |
|
61 |
||
62 |
if not user in event.organizers.all(): |
|
63 |
raise Http404 |
|
64 |
||
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
65 |
no_of_days = (event.stop_date - event.start_date).days |
39 | 66 |
days = range(1,no_of_days+2) |
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
67 |
|
39 | 68 |
feeds_list = [] |
69 |
for day in days: |
|
70 |
day_feeds = Feedback.objects.filter(event=event,day=day) |
|
71 |
if day_feeds.count(): |
|
72 |
day_list = [] |
|
73 |
for feed in day_feeds: |
|
74 |
day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace, |
|
75 |
feed.applicability, feed.problems, feed.exercises, feed.comments))) |
|
76 |
feeds_list.append(["Day %s"%day, day_list]) |
|
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
77 |
|
39 | 78 |
return render_to_response('list_feedbacks.html',{'user':user, 'event':event, 'feeds_list':feeds_list}) |
79 |