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