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/polls/models.py | 4 ++-- papillon/polls/views.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'papillon/polls') 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) -- cgit v1.2.3