feedback/views.py
author nishanth
Tue, 13 Apr 2010 15:15:13 +0530
changeset 35 79dc44b6edd4
parent 11 334550460bd7
child 36 cd0f61fa31f1
permissions -rw-r--r--
made a few redirects to 404

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

from django.http import HttpResponse

def submit_feedback(request, event_key):
    """ see if the ip address has already submitted a feedback.
    if not, collect the feedback.
    """

    try:
        event = Event.objects.get(key=event_key)
    except Event.DoesNotExist:
        raise Http404

    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)
    
    if request.method == "POST":
        form = FeedbackForm(request.POST)
        if form.is_valid():
            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:
        form = FeedbackForm()
        return render_to_response('feedback.html',{'form':form})

def list_feedbacks(request, event_key):
    """ print a list of all the feedbacks collected.
    """

    feeds = Feedback.objects.all()
    return render_to_response('list_feedbacks.html',{'feeds':feeds})