diff options
author | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-12-07 20:53:20 +0000 |
---|---|---|
committer | etienne <etienne@07715635-78ed-41b0-aaf1-0afda6c37f35> | 2008-12-07 20:53:20 +0000 |
commit | a0e093c353140308fc2fac24f1ec179e304ab3ba (patch) | |
tree | 7171188f2b9d4004d9346b313a02852b3c82eaff | |
parent | be9608d21e785ac9e2096f3753ebadbdbfa8f780 (diff) | |
download | Papillon-a0e093c353140308fc2fac24f1ec179e304ab3ba.tar.bz2 Papillon-a0e093c353140308fc2fac24f1ec179e304ab3ba.zip |
Comments
-rw-r--r-- | polls/models.py | 9 | ||||
-rw-r--r-- | polls/views.py | 16 | ||||
-rw-r--r-- | static/styles.css | 45 | ||||
-rw-r--r-- | templates/createOrEdit.html | 8 | ||||
-rw-r--r-- | 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 @@ <tr> <td></td> <td>{% if new %}<input type='hidden' name='new' value='1'/> - <input type='submit' value='{% trans "Create" %}' /> + <input type='submit' value='{% trans "Create" %}' class='submit'/> {% else %}<input type='hidden' name='edit' value='1'/> - <input type='submit' value='{% trans "Edit" %}' /> + <input type='submit' value='{% trans "Edit" %}' class='submit'/> {% endif %}</td> </tr> @@ -112,7 +112,7 @@ <tr> <td></td> <td><input type='hidden' name='edit' value='1'/> - <input type='submit' value='{% trans "Edit" %}' /></td> + <input type='submit' value='{% trans "Edit" %}' class='submit'/></td> </tr> </form>{% endif %} @@ -120,7 +120,7 @@ <tr><td><label>{% trans "New choice" %}</label></td><td><input type='text' name='new_choice'/></td><td>{%trans "Limited to"%} <input type='text' name='limit' class='limit'/> {%trans "vote(s)"%}</td><td class='form_description'>{% trans "Setting a new choice. Optionally you can set a limit of vote for this choice. This limit is usefull for limited resources allocation." %}</td></tr> <tr> <td></td> - <td><input type='hidden' name='add' value='1'/> <input type='submit' value='{% trans "Add" %}' /></td> + <td><input type='hidden' name='add' value='1'/> <input type='submit' value='{% trans "Add" %}' class='submit'/></td> </tr> </form> </table> 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 @@ </tr>{%endif%} </table> {% if poll.open %} - <input type='submit' value='{%if current_voter_id%}{% trans "Edit" %}{%else%}{% trans "Participate" %}{%endif%}'/> + <input type='submit' value='{%if current_voter_id%}{% trans "Edit" %}{%else%}{% trans "Participate" %}{%endif%}' class='submit'/> {% endif %} </div> <hr class='spacer'/> @@ -91,4 +91,25 @@ {%if hide_vote%}<p>{% trans "You have already vote? You are enough wise not to be influenced by other votes? You can display result by clicking" %} <a href='?display_result=1'>{% trans "here" %}</a>.</p>{%else%} <p>{% trans "Remain informed of poll evolution:" %} <a href="http://{{root_url}}feeds/poll/{{poll.base_url}}/">{%trans "Syndication"%}</a></p>{%endif%} </div> -{% endblock %} +{%if not hide_vote%} +<h3>{%trans "Comments"%}</h3> +<div class='comments'> + {%if poll.open%}<form method='post' action='{{base_url}}'> + <table class='comment'> + <tr> + <td><label for='comment_author'>{% trans "Author name" %}</label></td> + <td><input type='text' name='comment_author'/></td> + </tr> + <tr> + <td><label for='comment'>{% trans "Comment"%}</label></td> + <td><textarea name='comment'></textarea></td> + </tr> + <tr><td colspan='2' id='tdsubmit'><input type='submit' class='submit' value='{% trans "Send" %}'/></td></tr> + </table> +</form>{%endif%} + <ul>{%for comment in comments%} + <li><p class='author'>{{comment.author_name}}, {{comment.date|date:_("DATETIME_FORMAT")}} :</p> + <pre>{{comment.text}}</pre>{%endfor%} + </dl> +</div>{%endif%} +{% endblock %}
\ No newline at end of file |