feedback/views.py
changeset 55 53ff84c9192d
parent 44 7d748db0c7c3
child 56 3858a9d0f376
equal deleted inserted replaced
54:345d4413b85c 55:53ff84c9192d
     1 from django.shortcuts import render_to_response, redirect
     1 from django.shortcuts import render_to_response, redirect
     2 
     2 
     3 from workshop.reg.models import Event
     3 from workshop.reg.models import Event
     4 
     4 
     5 from workshop.feedback.models import Feedback
     5 from workshop.feedback.models import Feedback, FeedLog
     6 from workshop.feedback.forms import FeedbackForm
     6 from workshop.feedback.forms import FeedbackForm
     7 from workshop.feedback.utils import make_day_report
     7 from workshop.feedback.utils import make_day_report
     8 
     8 
     9 from django.http import HttpResponse
     9 from django.http import HttpResponse
    10 
    10 
    11 def submit_feedback(request, event_key):
    11 def submit_feedback(request, event_key):
    12     """ see if the ip address has already submitted a feedback.
    12     """ see if the ip address has already submitted a feedback.
    13     if not, collect the feedback.
    13     if not, collect the feedback.
    14     """
    14     """
    15 
    15 
       
    16     user = request.user
       
    17     if not (user.is_authenticated() and user.is_active):
       
    18         raise Http404
       
    19 
    16     try:
    20     try:
    17         event = Event.objects.get(key=event_key)
    21         event = Event.objects.get(key=event_key)
    18     except Event.DoesNotExist:
    22     except Event.DoesNotExist:
    19         raise Http404
    23         raise Http404
    20 
    24 
    21     if event.feedback_status == "0":
    25     if event.feedback_status == "0":
    22         raise Http404
    26         raise Http404
    23 
    27     
    24     user_ip = request.META["REMOTE_ADDR"]
       
    25     try:
    28     try:
    26         old_feedback = Feedback.objects.get(day=event.feedback_status, user_ip=user_ip)
    29         FeedLog.objects.get(user=user,day=event.feedback_status,event=event)
    27         return render_to_response('feedback.html', {'submitted':True})
    30         return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
    28     except Feedback.DoesNotExist:
    31     except FeedLog.DoesNotExist:
    29         new_feedback = Feedback(event=event, user_ip=user_ip, day=event.feedback_status)
    32         new_feedback = Feedback(event=event)
    30     
    33     
    31     if request.method == "POST":
    34     if request.method == "POST":
    32         form = FeedbackForm(request.POST)
    35         form = FeedbackForm(request.POST)
    33         if form.is_valid():
    36         if form.is_valid():
    34             data = form.cleaned_data
    37             data = form.cleaned_data
    39             new_feedback.applicability = data['applicability']
    42             new_feedback.applicability = data['applicability']
    40             new_feedback.problems = data['problems']
    43             new_feedback.problems = data['problems']
    41             new_feedback.exercises = data['exercises']
    44             new_feedback.exercises = data['exercises']
    42             new_feedback.comments = data['comments']
    45             new_feedback.comments = data['comments']
    43             new_feedback.save()
    46             new_feedback.save()
    44             return render_to_response('feedback.html', {'submitted':True})
    47         
       
    48             event.feedback_submitted_by.add(user)
       
    49             event.save()
       
    50 
       
    51             return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
    45         else:
    52         else:
    46             return render_to_response('feedback.html',{'form':form})
    53             return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
    47     else:
    54     else:
    48         form = FeedbackForm()
    55         form = FeedbackForm()
    49         return render_to_response('feedback.html',{'form':form})
    56         return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
    50 
    57 
    51 def list_feedbacks(request, event_key):
    58 def list_feedbacks(request, event_key):
    52     """ print a list of all the feedbacks collected.
    59     """ print a list of all the feedbacks collected.
    53     """
    60     """
    54 
    61