From 229e7616b16ee1f316b9a9ab5442631ff5033668 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 25 Oct 2011 00:53:14 +0200 Subject: Limit comments by poll (closes #310) --- papillon/locale/fr/LC_MESSAGES/django.po | 14 +++++++++----- papillon/polls/models.py | 4 ++-- papillon/polls/views.py | 3 +++ papillon/settings.py.tpl | 1 + papillon/templates/vote.html | 6 +++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/papillon/locale/fr/LC_MESSAGES/django.po b/papillon/locale/fr/LC_MESSAGES/django.po index 4d09e84..af612c7 100644 --- a/papillon/locale/fr/LC_MESSAGES/django.po +++ b/papillon/locale/fr/LC_MESSAGES/django.po @@ -1,5 +1,5 @@ # Papillon -# Copyright (C) 2008 +# Copyright (C) 2008-2011 # This file is distributed under the same license as the papillon package. # Étienne Loks , 2008. # @@ -8,10 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2009-12-04 23:49+0100\n" +"POT-Creation-Date: 2011-10-25 00:49+0200\n" "PO-Revision-Date: 2008-08-20 00:22+0200\n" "Last-Translator: Étienne Loks ,\n" "Language-Team: fr\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -282,8 +283,7 @@ msgstr "Retourner au sondage" msgid "Choices" msgstr "Choix" -#: templates/editChoicesUser.html:21 templates/vote.html:23 -#: templates/vote.html.py:144 +#: templates/editChoicesUser.html:21 templates/vote.html:144 msgid "DATETIME_FORMAT" msgstr "" @@ -358,6 +358,11 @@ msgstr "syndication" msgid "Comments" msgstr "Commentaires" +#: templates/vote.html:128 +#, python-format +msgid "%(max_comment_nb)s max" +msgstr "%(max_comment_nb)s maximum" + #: templates/vote.html:137 msgid "Comment" msgstr "Commentaire" @@ -381,4 +386,3 @@ msgid ": %(sum)s vote" msgid_plural ": %(sum)s votes" msgstr[0] " : %(sum)s vote" msgstr[1] " : %(sum)s votes" - diff --git a/papillon/polls/models.py b/papillon/polls/models.py index f8b3b22..411e75f 100644 --- a/papillon/polls/models.py +++ b/papillon/polls/models.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2008 Étienne Loks +# Copyright (C) 2008-2011 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -138,7 +138,7 @@ the poll/check this option to reopen it")) class Comment(models.Model): '''Comment for a poll''' - poll = models.ForeignKey(Poll) + poll = models.ForeignKey(Poll, related_name='comments') author_name = models.CharField(max_length=100) text = models.CharField(max_length=1000) date = models.DateTimeField(auto_now_add=True) diff --git a/papillon/polls/views.py b/papillon/polls/views.py index 75823be..1022f58 100644 --- a/papillon/polls/views.py +++ b/papillon/polls/views.py @@ -333,6 +333,8 @@ def poll(request, poll_url): v.save() def newComment(request, poll): "Comment the poll" + if poll.comments.count() >= settings.MAX_COMMENT_NB: + return if 'comment_author' not in request.POST \ or not request.POST['comment_author'] \ or not request.POST['comment']: @@ -486,4 +488,5 @@ def poll(request, poll_url): if 'knowned_vote_' + poll.base_url in request.session: response_dct['hide_vote'] = False response_dct['form_comment'] = CommentForm() + response_dct['max_comment_nb'] = settings.MAX_COMMENT_NB return render_to_response('vote.html', response_dct) diff --git a/papillon/settings.py.tpl b/papillon/settings.py.tpl index 7ca2761..b40a37e 100644 --- a/papillon/settings.py.tpl +++ b/papillon/settings.py.tpl @@ -14,6 +14,7 @@ EXTRA_URL = 'papillon/' BASE_SITE = SERVER_URL + EXTRA_URL TINYMCE_URL = 'http://localhost/tinymce/' +MAX_COMMENT_NB = 10 # max number of comments by poll - 0 to disable comments # time to live in days DAYS_TO_LIVE = 30 diff --git a/papillon/templates/vote.html b/papillon/templates/vote.html index dc384f5..5c20e5c 100644 --- a/papillon/templates/vote.html +++ b/papillon/templates/vote.html @@ -124,10 +124,10 @@ {%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%} -{%if not hide_vote%} -

{%trans "Comments"%}

+{%if not hide_vote and max_comment_nb %} +

{%trans "Comments"%} ({% blocktrans %}{{max_comment_nb}} max{% endblocktrans %})

- {%if poll.open%}
+ {%if poll.open and max_comment_nb > poll.comments.count %} -- cgit v1.2.3