From 023f8571e1386a08e25d779252c221ca939d1f1d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 25 Oct 2011 01:13:25 +0200 Subject: Allow disabling frontpage polls (closes #311) --- .gitignore | 1 + papillon/polls/forms.py | 4 +++- papillon/polls/views.py | 6 ++++-- papillon/settings.py.tpl | 1 + papillon/templates/base.html | 2 +- papillon/templates/main.html | 3 ++- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2b0f79c..0363bf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc *.db *.swp +*.mo papillon/settings.py diff --git a/papillon/polls/forms.py b/papillon/polls/forms.py index 3a151aa..2e9b75d 100644 --- a/papillon/polls/forms.py +++ b/papillon/polls/forms.py @@ -28,7 +28,7 @@ from django.contrib.admin import widgets as adminwidgets from django.utils.translation import gettext_lazy as _ from papillon.polls.models import Poll, Category, Choice, Comment -from papillon import settings +from django.conf import settings class TextareaWidget(forms.Textarea): """ @@ -73,6 +73,8 @@ class AdminPollForm(PollForm): 'dated_choices', 'type'] if not Category.objects.all(): exclude.append('category') + if not settings.ALLOW_FRONTPAGE_POLL: + exclude.append('public') enddate = SplitDateTimeJSField(widget=adminwidgets.AdminSplitDateTime(), required=False, label=Poll._meta.get_field('enddate').verbose_name, help_text=Poll._meta.get_field('enddate').help_text) diff --git a/papillon/polls/views.py b/papillon/polls/views.py index 1022f58..26b3b34 100644 --- a/papillon/polls/views.py +++ b/papillon/polls/views.py @@ -58,8 +58,10 @@ def index(request): response_dct, redirect = getBaseResponse(request) if redirect: return redirect - response_dct['polls'] = Poll.objects.filter(public=True, category=None) - response_dct['categories'] = Category.objects.all() + response_dct['public'] = settings.ALLOW_FRONTPAGE_POLL + if response_dct['public']: + response_dct['polls'] = Poll.objects.filter(public=True, category=None) + response_dct['categories'] = Category.objects.all() error = '' if 'bad_poll' in request.GET: response_dct['error'] = _("The poll requested don't exist (anymore?)") diff --git a/papillon/settings.py.tpl b/papillon/settings.py.tpl index b40a37e..f83dcb2 100644 --- a/papillon/settings.py.tpl +++ b/papillon/settings.py.tpl @@ -15,6 +15,7 @@ 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 +ALLOW_FRONTPAGE_POLL = False # disabled is recommanded for public instance # time to live in days DAYS_TO_LIVE = 30 diff --git a/papillon/templates/base.html b/papillon/templates/base.html index 5da20fb..30b1bf3 100644 --- a/papillon/templates/base.html +++ b/papillon/templates/base.html @@ -19,7 +19,7 @@ {% block content %}{% endblock %} diff --git a/papillon/templates/main.html b/papillon/templates/main.html index f27a97b..696ab47 100644 --- a/papillon/templates/main.html +++ b/papillon/templates/main.html @@ -6,6 +6,7 @@

{%trans "Create a poll"%}

{% trans "Create a new sondage for take a decision, find a date for a meeting, etc." %} {% trans "It's here!" %}

+{% if public %} {% if polls %}

{%trans "Public polls"%}

{%endif%} {% for poll in polls %}
@@ -18,5 +19,5 @@ {% for category in categories %}

{{category.name}}

{% endfor %} - +{% endif %} {% endblock %} -- cgit v1.2.3