feedback/views.py
changeset 11 334550460bd7
parent 10 c52d170969f0
child 35 79dc44b6edd4
--- a/feedback/views.py	Mon Apr 12 04:23:13 2010 +0530
+++ b/feedback/views.py	Mon Apr 12 11:23:27 2010 +0530
@@ -1,5 +1,7 @@
 from django.shortcuts import render_to_response, redirect
 
+from workshop.reg.models import Event
+
 from workshop.feedback.models import Feedback
 from workshop.feedback.forms import FeedbackForm
 
@@ -10,14 +12,35 @@
     if not, collect the feedback.
     """
 
-    ip = request.META["REMOTE_ADDR"]
-    print 'ip', ip
+    try:
+        event = Event.objects.get(key=event_key)
+    except Event.DoesNotExist:
+        return redirect('/reg')
+
+    if event.feedback_status == "0":
+        return redirect('/reg')
+
+    user_ip = request.META["REMOTE_ADDR"]
+    try:
+        old_feedback = Feedback.objects.get(day=event.feedback_status, user_ip=user_ip)
+        return render_to_response('feedback.html', {'submitted':True})
+    except:
+        new_feedback = Feedback(event=event, user_ip=user_ip, day=event.feedback_status)
     
     if request.method == "POST":
         form = FeedbackForm(request.POST)
         if form.is_valid():
-            form.save()
-            return HttpResponse('Good. now click <a href="/feedback/list">here</a>')
+            data = form.cleaned_data
+            new_feedback.topics = data['topics']  
+            new_feedback.depth = data['depth']
+            new_feedback.methodology = data['methodology']
+            new_feedback.pace = data['pace']
+            new_feedback.applicability = data['applicability']
+            new_feedback.problems = data['problems']
+            new_feedback.exercises = data['exercises']
+            new_feedback.comments = data['comments']
+            new_feedback.save()
+            return render_to_response('feedback.html', {'submitted':True})
         else:
             return render_to_response('feedback.html',{'form':form})
     else: