added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
--- a/feedback/models.py Thu Apr 15 18:27:38 2010 +0530
+++ b/feedback/models.py Thu Apr 15 18:57:55 2010 +0530
@@ -64,3 +64,11 @@
def __unicode__(self):
return unicode(self.event.title)
+
+class FeedLog(models.Model):
+ """ A model to store the days for which a user had submitted feedback.
+ """
+
+ event = models.ForeignKey(Event)
+ user = models.ForeignKey(User)
+ day = models.CharField(max_length=1)
--- a/feedback/views.py Thu Apr 15 18:27:38 2010 +0530
+++ b/feedback/views.py Thu Apr 15 18:57:55 2010 +0530
@@ -2,7 +2,7 @@
from workshop.reg.models import Event
-from workshop.feedback.models import Feedback
+from workshop.feedback.models import Feedback, FeedLog
from workshop.feedback.forms import FeedbackForm
from workshop.feedback.utils import make_day_report
@@ -13,6 +13,10 @@
if not, collect the feedback.
"""
+ user = request.user
+ if not (user.is_authenticated() and user.is_active):
+ raise Http404
+
try:
event = Event.objects.get(key=event_key)
except Event.DoesNotExist:
@@ -20,13 +24,12 @@
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)
+ FeedLog.objects.get(user=user,day=event.feedback_status,event=event)
+ return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
+ except FeedLog.DoesNotExist:
+ new_feedback = Feedback(event=event)
if request.method == "POST":
form = FeedbackForm(request.POST)
@@ -41,12 +44,16 @@
new_feedback.exercises = data['exercises']
new_feedback.comments = data['comments']
new_feedback.save()
- return render_to_response('feedback.html', {'submitted':True})
+
+ event.feedback_submitted_by.add(user)
+ event.save()
+
+ return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
else:
- return render_to_response('feedback.html',{'form':form})
+ return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
else:
form = FeedbackForm()
- return render_to_response('feedback.html',{'form':form})
+ return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
def list_feedbacks(request, event_key):
""" print a list of all the feedbacks collected.
--- a/reg/views.py Thu Apr 15 18:27:38 2010 +0530
+++ b/reg/views.py Thu Apr 15 18:57:55 2010 +0530
@@ -13,7 +13,7 @@
from workshop.reg import forms as reg_forms
from workshop.reg import events as reg_events
-from workshop.feedback.models import Feedback
+from workshop.feedback.models import Feedback, FeedLog
def homepage(request):
""" see if the user is active.
@@ -199,8 +199,8 @@
can_submit_feedback = False
if not event.feedback_status == "0":
try:
- event.feedback.get(user_ip__iexact=user_ip, day=event.feedback_status)
- except Feedback.DoesNotExist:
+ FeedLog.objects.get(user=user,event=event,day=event.feedback_status)
+ except FeedLog.DoesNotExist:
can_submit_feedback = True
context = {'user': user,
--- a/templates/feedback.html Thu Apr 15 18:27:38 2010 +0530
+++ b/templates/feedback.html Thu Apr 15 18:57:55 2010 +0530
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% block content %}
+Feedback on Day {{event.feedback_status}} of {{event.title}} at {{event.venue}}
{% if submitted %}
Your feedback has been successfully submitted.
{% else %}