summaryrefslogtreecommitdiff
path: root/polls
diff options
context:
space:
mode:
authoretienne2008-12-07 20:53:20 +0000
committeretienne2008-12-07 20:53:20 +0000
commita0e093c353140308fc2fac24f1ec179e304ab3ba (patch)
tree7171188f2b9d4004d9346b313a02852b3c82eaff /polls
parentbe9608d21e785ac9e2096f3753ebadbdbfa8f780 (diff)
Comments
Diffstat (limited to 'polls')
-rw-r--r--polls/models.py9
-rw-r--r--polls/views.py16
2 files changed, 24 insertions, 1 deletions
diff --git a/polls/models.py b/polls/models.py
index dac3d39..dabb27e 100644
--- a/polls/models.py
+++ b/polls/models.py
@@ -63,6 +63,15 @@ class Poll(models.Model):
def __unicode__(self):
return self.name
+class Comment(models.Model):
+ '''Comment for a poll'''
+ poll = models.ForeignKey(Poll)
+ author_name = models.CharField(max_length=100)
+ text = models.CharField(max_length=1000)
+ date = models.DateTimeField(auto_now_add=True)
+ class Meta:
+ ordering = ['date']
+
class Voter(models.Model):
user = models.ForeignKey(PollUser)
poll = models.ForeignKey(Poll)
diff --git a/polls/views.py b/polls/views.py
index 0ab23b7..f42f854 100644
--- a/polls/views.py
+++ b/polls/views.py
@@ -31,7 +31,8 @@ from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from papillon.settings import LANGUAGES
-from papillon.polls.models import Poll, PollUser, Choice, Voter, Vote, Category
+from papillon.polls.models import Poll, PollUser, Choice, Voter, Vote, \
+ Category, Comment
def getBaseResponse(request):
"""Manage basic fields for the template
@@ -364,6 +365,15 @@ def poll(request, poll_url):
# a new choice
v = Vote(voter=voter, choice=choice, value=0)
v.save()
+ def newComment(request, poll):
+ "Comment the poll"
+ if 'comment_author' not in request.POST \
+ or not request.POST['comment_author'] \
+ or not request.POST['comment']:
+ return
+ c = Comment(poll=poll, author_name=request.POST['comment_author'],
+ text=request.POST['comment'])
+ c.save()
def newVote(request, choices):
"Create new votes"
@@ -449,6 +459,9 @@ def poll(request, poll_url):
newVote(request, choices)
# update the modification date of the poll
poll.save()
+ if 'comment' in request.POST and poll.open:
+ # comment posted
+ newComment(request, poll)
# 'voter' is in request.GET when the edit button is pushed
if 'voter' in request.GET and poll.open:
@@ -501,6 +514,7 @@ def poll(request, poll_url):
choice.save()
response_dct['voters'] = voters
response_dct['choices'] = choices
+ response_dct['comments'] = Comment.objects.filter(poll=poll)
# verify if vote's result has to be displayed
response_dct['hide_vote'] = True
if u'display_result' in request.GET: