From a0e093c353140308fc2fac24f1ec179e304ab3ba Mon Sep 17 00:00:00 2001 From: etienne Date: Sun, 7 Dec 2008 20:53:20 +0000 Subject: Comments --- polls/models.py | 9 +++++++++ polls/views.py | 16 +++++++++++++++- static/styles.css | 45 +++++++++++++++++++++++++++++++++++++++++++++ templates/createOrEdit.html | 8 ++++---- templates/vote.html | 25 +++++++++++++++++++++++-- 5 files changed, 96 insertions(+), 7 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: diff --git a/static/styles.css b/static/styles.css index 64eb77b..e707971 100644 --- a/static/styles.css +++ b/static/styles.css @@ -24,6 +24,11 @@ font-family: Arial, Verdana, Geneva, "Bitstream Vera Sans", Helvetica, sans-seri background-color:#ced3e1; } +pre{ +font-size:12px; +font-family: Arial, Verdana, Geneva, "Bitstream Vera Sans", Helvetica, sans-serif; +} + a{ color:#6f819d; } @@ -150,6 +155,10 @@ width:600px; width:160px; } +.new_poll .submit{ +width:auto; +} + .new_poll input.limit{ width:20px; } @@ -261,4 +270,40 @@ border:1px solid lightgrey; .poll-description p{ margin:0; padding:2px; +} + + +.comments ul{ +list-style-type:None; +margin:4px; +padding:0; +} + +.comments li{ +margin:4px; +padding:4px; +border:1px solid lightgrey; +} + +.comments .author{ +margin:0; +color:#6f819d; +padding:0; +} + +.comments input{ +width:160px; +} + +.comments textarea{ +width:160px; +height:100px; +} + +.comments #tdsubmit{ +text-align:center; +} + +.comments .submit{ +width:auto; } \ No newline at end of file diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html index e4d9639..2158527 100644 --- a/templates/createOrEdit.html +++ b/templates/createOrEdit.html @@ -91,9 +91,9 @@ {% if new %} - + {% else %} - + {% endif %} @@ -112,7 +112,7 @@ - + {% endif %} @@ -120,7 +120,7 @@ {%trans "Limited to"%} {%trans "vote(s)"%}{% trans "Setting a new choice. Optionally you can set a limit of vote for this choice. This limit is usefull for limited resources allocation." %} - + diff --git a/templates/vote.html b/templates/vote.html index b9cfa98..3deacf5 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -82,7 +82,7 @@ {%endif%} {% if poll.open %} - + {% endif %}
@@ -91,4 +91,25 @@ {%if hide_vote%}

{% trans "You have already vote? You are enough wise not to be influenced by other votes? You can display result by clicking" %} {% trans "here" %}.

{%else%}

{% trans "Remain informed of poll evolution:" %} {%trans "Syndication"%}

{%endif%} -{% endblock %} +{%if not hide_vote%} +

{%trans "Comments"%}

+
+ {%if poll.open%}
+ + + + + + + + + + +
+
{%endif%} +
{%endif%} +{% endblock %} \ No newline at end of file -- cgit v1.2.3