feedback/views.py
changeset 5 37e4027fba48
parent 0 30a0f9e20fd4
child 10 c52d170969f0
equal deleted inserted replaced
4:ededea9ad08b 5:37e4027fba48
     1 # Create your views here.
     1 from django.shortcuts import render_to_response, redirect
       
     2 
       
     3 from workshop.feedback.models import Feedback
       
     4 from workshop.feedback.forms import FeedbackForm
       
     5 
       
     6 from django.http import HttpResponse
       
     7 
       
     8 def submit_feedback(request):
       
     9     """ see if the ip address has already submitted a feedback.
       
    10     if not, collect the feedback.
       
    11     """
       
    12 
       
    13     ip = request.META["REMOTE_ADDR"]
       
    14     print 'ip', ip
       
    15     
       
    16     if request.method == "POST":
       
    17         form = FeedbackForm(request.POST)
       
    18         if form.is_valid():
       
    19             form.save()
       
    20             return HttpResponse('Good. now click <a href="/feedback/list">here</a>')
       
    21         else:
       
    22             return render_to_response('feedback.html',{'form':form})
       
    23     else:
       
    24         form = FeedbackForm()
       
    25         return render_to_response('feedback.html',{'form':form})
       
    26 
       
    27 def list_feedbacks(request):
       
    28     """ print a list of all the feedbacks collected.
       
    29     """
       
    30 
       
    31     feeds = Feedback.objects.all()
       
    32     return render_to_response('list_feedbacks.html',{'feeds':feeds})