author | nishanth |
Tue, 29 Jun 2010 16:12:29 +0530 | |
changeset 103 | ee9261c5ba18 |
parent 97 | 87d522d28a28 |
permissions | -rwxr-xr-x |
5 | 1 |
from django.shortcuts import render_to_response, redirect |
2 |
||
62
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
56
diff
changeset
|
3 |
from ws_app.reg.models import Event |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
4 |
|
62
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
56
diff
changeset
|
5 |
from ws_app.feedback.models import Feedback, FeedLog |
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
56
diff
changeset
|
6 |
from ws_app.feedback.forms import FeedbackForm |
b7e47cc39342
renamed the project to ws_app and modified imports accordingly .
nishanth
parents:
56
diff
changeset
|
7 |
from ws_app.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 |
|
56
3858a9d0f376
removed the field feedback_submitted_by from event model and added the code to create feedlog record when a new feedback is taken.
nishanth
parents:
55
diff
changeset
|
48 |
FeedLog(user=user, event=event, day=event.feedback_status).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
|
49 |
|
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 |
return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event}) |
5 | 51 |
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
|
52 |
return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event}) |
5 | 53 |
else: |
54 |
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
|
55 |
return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event}) |
5 | 56 |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
5
diff
changeset
|
57 |
def list_feedbacks(request, event_key): |
5 | 58 |
""" print a list of all the feedbacks collected. |
59 |
""" |
|
60 |
||
36 | 61 |
user = request.user |
62 |
||
63 |
try: |
|
64 |
event = Event.objects.get(key__iexact=event_key) |
|
65 |
except Event.DoesNotExist: |
|
66 |
raise Http404 |
|
67 |
||
68 |
if not user in event.organizers.all(): |
|
69 |
raise Http404 |
|
70 |
||
38
b63b78017225
added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents:
36
diff
changeset
|
71 |
no_of_days = (event.stop_date - event.start_date).days |
39 | 72 |
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
|
73 |
|
39 | 74 |
feeds_list = [] |
75 |
for day in days: |
|
76 |
day_feeds = Feedback.objects.filter(event=event,day=day) |
|
77 |
if day_feeds.count(): |
|
78 |
day_list = [] |
|
79 |
for feed in day_feeds: |
|
80 |
day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace, |
|
81 |
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
|
82 |
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
|
83 |
|
39 | 84 |
return render_to_response('list_feedbacks.html',{'user':user, 'event':event, 'feeds_list':feeds_list}) |
85 |
||
41
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
86 |
def view_report(request, event_key): |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
87 |
""" compile the report and display it. |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
88 |
""" |
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 |
user = request.user |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
91 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
92 |
try: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
93 |
event = Event.objects.get(key__iexact=event_key) |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
94 |
except Event.DoesNotExist: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
95 |
raise Http404 |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
96 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
97 |
if not user in event.organizers.all(): |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
98 |
raise Http404 |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
99 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
100 |
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
|
101 |
days = range(1,no_of_days+2) |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
102 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
103 |
workshop_report = [] |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
104 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
105 |
for day in days: |
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
106 |
day_num = str(day) |
97
87d522d28a28
now comments are also displayed on view report page.
nishanth
parents:
96
diff
changeset
|
107 |
day_feeds = event.feedback.filter(day=day_num) |
44
7d748db0c7c3
now show report page does not show report if there are no feedbacks .
nishanth
parents:
41
diff
changeset
|
108 |
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
|
109 |
if day_report: |
97
87d522d28a28
now comments are also displayed on view report page.
nishanth
parents:
96
diff
changeset
|
110 |
day_comments = [ feed.comments for feed in day_feeds if feed.comments ] |
87d522d28a28
now comments are also displayed on view report page.
nishanth
parents:
96
diff
changeset
|
111 |
day_report.extend(["General comments:",day_comments]) |
44
7d748db0c7c3
now show report page does not show report if there are no feedbacks .
nishanth
parents:
41
diff
changeset
|
112 |
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
|
113 |
|
ab0a8a72b069
added view report functionality. have to make it look better.
nishanth
parents:
39
diff
changeset
|
114 |
return render_to_response("show_report.html", {"user":user, "event":event, "workshop_report":workshop_report}) |