author | nishanth |
Thu, 15 Apr 2010 18:57:55 +0530 | |
changeset 55 | 53ff84c9192d |
parent 44 | 7d748db0c7c3 |
child 56 | 3858a9d0f376 |
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 |
|
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
5 |
from workshop.feedback.models import Feedback, FeedLog |
5 | 6 |
from workshop.feedback.forms import FeedbackForm |
41
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
7 |
from workshop.feedback.utils import make_day_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 |
||
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
16 |
user = request.user |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
17 |
if not (user.is_authenticated() and user.is_active): |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
18 |
raise Http404 |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
19 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
20 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
21 |
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
|
22 |
except Event.DoesNotExist: |
35 | 23 |
raise Http404 |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
24 |
|
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
25 |
if event.feedback_status == "0": |
35 | 26 |
raise Http404 |
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
27 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
28 |
try: |
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
29 |
FeedLog.objects.get(user=user,day=event.feedback_status,event=event) |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
30 |
return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event}) |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
31 |
except FeedLog.DoesNotExist: |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
32 |
new_feedback = Feedback(event=event) |
5 | 33 |
|
34 |
if request.method == "POST": |
|
35 |
form = FeedbackForm(request.POST) |
|
36 |
if form.is_valid(): |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
37 |
data = form.cleaned_data |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
38 |
new_feedback.topics = data['topics'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
39 |
new_feedback.depth = data['depth'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
40 |
new_feedback.methodology = data['methodology'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
41 |
new_feedback.pace = data['pace'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
42 |
new_feedback.applicability = data['applicability'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
43 |
new_feedback.problems = data['problems'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
44 |
new_feedback.exercises = data['exercises'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
45 |
new_feedback.comments = data['comments'] |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
46 |
new_feedback.save() |
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
47 |
|
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
48 |
event.feedback_submitted_by.add(user) |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
49 |
event.save() |
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
50 |
|
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
51 |
return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event}) |
5 | 52 |
else: |
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
53 |
return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event}) |
5 | 54 |
else: |
55 |
form = FeedbackForm() |
|
55
53ff84c9192d
added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents:
44
diff
changeset
|
56 |
return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event}) |
5 | 57 |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
5
diff
changeset
|
58 |
def list_feedbacks(request, event_key): |
5 | 59 |
""" print a list of all the feedbacks collected. |
60 |
""" |
|
61 |
||
36 | 62 |
user = request.user |
63 |
||
64 |
try: |
|
65 |
event = Event.objects.get(key__iexact=event_key) |
|
66 |
except Event.DoesNotExist: |
|
67 |
raise Http404 |
|
68 |
||
69 |
if not user in event.organizers.all(): |
|
70 |
raise Http404 |
|
71 |
||
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
72 |
no_of_days = (event.stop_date - event.start_date).days |
39 | 73 |
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
|
74 |
|
39 | 75 |
feeds_list = [] |
76 |
for day in days: |
|
77 |
day_feeds = Feedback.objects.filter(event=event,day=day) |
|
78 |
if day_feeds.count(): |
|
79 |
day_list = [] |
|
80 |
for feed in day_feeds: |
|
81 |
day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace, |
|
82 |
feed.applicability, feed.problems, feed.exercises, feed.comments))) |
|
41
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
83 |
feeds_list.extend(["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
|
84 |
|
39 | 85 |
return render_to_response('list_feedbacks.html',{'user':user, 'event':event, 'feeds_list':feeds_list}) |
86 |
||
41
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
87 |
def view_report(request, event_key): |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
88 |
""" compile the report and display it. |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
89 |
""" |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
90 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
91 |
user = request.user |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
92 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
93 |
try: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
94 |
event = Event.objects.get(key__iexact=event_key) |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
95 |
except Event.DoesNotExist: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
96 |
raise Http404 |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
97 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
98 |
if not user in event.organizers.all(): |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
99 |
raise Http404 |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
100 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
101 |
no_of_days = (event.stop_date - event.start_date).days |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
102 |
days = range(1,no_of_days+2) |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
103 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
104 |
workshop_report = [] |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
105 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
106 |
for day in days: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
107 |
day_num = str(day) |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
108 |
day_feeds = Feedback.objects.filter(event=event,day=day_num) |
44
7d748db0c7c3
now show report page does not show report if there are no feedbacks .
nishanth
parents:
41
diff
changeset
|
109 |
day_report = make_day_report(day_feeds) |
7d748db0c7c3
now show report page does not show report if there are no feedbacks .
nishanth
parents:
41
diff
changeset
|
110 |
if day_report: |
7d748db0c7c3
now show report page does not show report if there are no feedbacks .
nishanth
parents:
41
diff
changeset
|
111 |
workshop_report.extend( [ "Day %s"%day_num, day_report] ) |
41
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
112 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
113 |
return render_to_response("show_report.html", {"user":user, "event":event, "workshop_report":workshop_report}) |