1 from django.shortcuts import render_to_response, redirect |
1 from django.shortcuts import render_to_response, redirect |
|
2 |
|
3 from workshop.reg.models import Event |
2 |
4 |
3 from workshop.feedback.models import Feedback |
5 from workshop.feedback.models import Feedback |
4 from workshop.feedback.forms import FeedbackForm |
6 from workshop.feedback.forms import FeedbackForm |
5 |
7 |
6 from django.http import HttpResponse |
8 from django.http import HttpResponse |
8 def submit_feedback(request, event_key): |
10 def submit_feedback(request, event_key): |
9 """ see if the ip address has already submitted a feedback. |
11 """ see if the ip address has already submitted a feedback. |
10 if not, collect the feedback. |
12 if not, collect the feedback. |
11 """ |
13 """ |
12 |
14 |
13 ip = request.META["REMOTE_ADDR"] |
15 try: |
14 print 'ip', ip |
16 event = Event.objects.get(key=event_key) |
|
17 except Event.DoesNotExist: |
|
18 return redirect('/reg') |
|
19 |
|
20 if event.feedback_status == "0": |
|
21 return redirect('/reg') |
|
22 |
|
23 user_ip = request.META["REMOTE_ADDR"] |
|
24 try: |
|
25 old_feedback = Feedback.objects.get(day=event.feedback_status, user_ip=user_ip) |
|
26 return render_to_response('feedback.html', {'submitted':True}) |
|
27 except: |
|
28 new_feedback = Feedback(event=event, user_ip=user_ip, day=event.feedback_status) |
15 |
29 |
16 if request.method == "POST": |
30 if request.method == "POST": |
17 form = FeedbackForm(request.POST) |
31 form = FeedbackForm(request.POST) |
18 if form.is_valid(): |
32 if form.is_valid(): |
19 form.save() |
33 data = form.cleaned_data |
20 return HttpResponse('Good. now click <a href="/feedback/list">here</a>') |
34 new_feedback.topics = data['topics'] |
|
35 new_feedback.depth = data['depth'] |
|
36 new_feedback.methodology = data['methodology'] |
|
37 new_feedback.pace = data['pace'] |
|
38 new_feedback.applicability = data['applicability'] |
|
39 new_feedback.problems = data['problems'] |
|
40 new_feedback.exercises = data['exercises'] |
|
41 new_feedback.comments = data['comments'] |
|
42 new_feedback.save() |
|
43 return render_to_response('feedback.html', {'submitted':True}) |
21 else: |
44 else: |
22 return render_to_response('feedback.html',{'form':form}) |
45 return render_to_response('feedback.html',{'form':form}) |
23 else: |
46 else: |
24 form = FeedbackForm() |
47 form = FeedbackForm() |
25 return render_to_response('feedback.html',{'form':form}) |
48 return render_to_response('feedback.html',{'form':form}) |