feedback/views.py
changeset 55 53ff84c9192d
parent 44 7d748db0c7c3
child 56 3858a9d0f376
--- a/feedback/views.py	Thu Apr 15 18:27:38 2010 +0530
+++ b/feedback/views.py	Thu Apr 15 18:57:55 2010 +0530
@@ -2,7 +2,7 @@
 
 from workshop.reg.models import Event
 
-from workshop.feedback.models import Feedback
+from workshop.feedback.models import Feedback, FeedLog
 from workshop.feedback.forms import FeedbackForm
 from workshop.feedback.utils import make_day_report
 
@@ -13,6 +13,10 @@
     if not, collect the feedback.
     """
 
+    user = request.user
+    if not (user.is_authenticated() and user.is_active):
+        raise Http404
+
     try:
         event = Event.objects.get(key=event_key)
     except Event.DoesNotExist:
@@ -20,13 +24,12 @@
 
     if event.feedback_status == "0":
         raise Http404
-
-    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 Feedback.DoesNotExist:
-        new_feedback = Feedback(event=event, user_ip=user_ip, day=event.feedback_status)
+        FeedLog.objects.get(user=user,day=event.feedback_status,event=event)
+        return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
+    except FeedLog.DoesNotExist:
+        new_feedback = Feedback(event=event)
     
     if request.method == "POST":
         form = FeedbackForm(request.POST)
@@ -41,12 +44,16 @@
             new_feedback.exercises = data['exercises']
             new_feedback.comments = data['comments']
             new_feedback.save()
-            return render_to_response('feedback.html', {'submitted':True})
+        
+            event.feedback_submitted_by.add(user)
+            event.save()
+
+            return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
         else:
-            return render_to_response('feedback.html',{'form':form})
+            return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
     else:
         form = FeedbackForm()
-        return render_to_response('feedback.html',{'form':form})
+        return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
 
 def list_feedbacks(request, event_key):
     """ print a list of all the feedbacks collected.