feedback/views.py
author nishanth
Mon, 19 Apr 2010 22:36:23 +0530
changeset 5 9a671f3eb24c
parent 1 5d921672ef41
child 7 dfedb369f32e
permissions -rw-r--r--
created the add feedback functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     1
from django.shortcuts import render_to_response
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     2
from django.http import Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     3
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     4
from offline.event.models import Event
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     5
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     6
from offline.feedback.models import Feedback
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     7
from offline.feedback.forms import FeedbackForm
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     8
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     9
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    10
def submit_feedback(request):
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    11
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    12
    """ see if the ip address has already submitted a feedback.
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    13
    if not, collect the feedback.
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    14
    """
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    15
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    16
    try:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    17
        event = Event.objects.all()[0]
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    18
    except IndexError:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    19
        raise Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    20
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    21
    if event.feedback_status == "0":
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    22
        raise Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    23
    else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    24
        day = event.feedback_status
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    25
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    26
    ip = request.META['REMOTE_ADDR']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    27
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    28
    try:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    29
        Feedback.objects.get(event=event,day=day,user_ip=ip)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    30
        return render_to_response('submit_feedback.html', {'submitted':True, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    31
    except Feedback.DoesNotExist:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    32
        new_feedback = Feedback(event=event,day=day,user_ip=ip)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    33
       
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    34
    if request.method == "POST":
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    35
        form = FeedbackForm(request.POST)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    36
        if form.is_valid():
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    37
            data = form.cleaned_data
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    38
            new_feedback.topics = data['topics']  
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    39
            new_feedback.depth = data['depth']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    40
            new_feedback.methodology = data['methodology']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    41
            new_feedback.pace = data['pace']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    42
            new_feedback.applicability = data['applicability']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    43
            new_feedback.problems = data['problems']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    44
            new_feedback.exercises = data['exercises']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    45
            new_feedback.comments = data['comments']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    46
            new_feedback.save()
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    47
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    48
            return render_to_response('submit_feedback.html', {'submitted':True, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    49
        else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    50
            return render_to_response('submit_feedback.html',{ 'form':form, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    51
    else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    52
        form = FeedbackForm()
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    53
        return render_to_response('submit_feedback.html',{'form':form, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    54