feedback/views.py
changeset 5 37e4027fba48
parent 0 30a0f9e20fd4
child 10 c52d170969f0
--- a/feedback/views.py	Fri Apr 09 12:28:58 2010 +0530
+++ b/feedback/views.py	Fri Apr 09 13:21:46 2010 +0530
@@ -1,1 +1,32 @@
-# Create your views here.
+from django.shortcuts import render_to_response, redirect
+
+from workshop.feedback.models import Feedback
+from workshop.feedback.forms import FeedbackForm
+
+from django.http import HttpResponse
+
+def submit_feedback(request):
+    """ see if the ip address has already submitted a feedback.
+    if not, collect the feedback.
+    """
+
+    ip = request.META["REMOTE_ADDR"]
+    print 'ip', ip
+    
+    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>')
+        else:
+            return render_to_response('feedback.html',{'form':form})
+    else:
+        form = FeedbackForm()
+        return render_to_response('feedback.html',{'form':form})
+
+def list_feedbacks(request):
+    """ print a list of all the feedbacks collected.
+    """
+
+    feeds = Feedback.objects.all()
+    return render_to_response('list_feedbacks.html',{'feeds':feeds})