From aedea8f1939ae9f894670b461abea9bea1be092e Mon Sep 17 00:00:00 2001 From: etienne Date: Fri, 5 Dec 2008 00:16:29 +0000 Subject: Public votes - Polls categories --- polls/models.py | 13 +++++++++--- polls/views.py | 44 +++++++++++++++++++++++++++++++++------ static/styles.css | 15 ++++++++++++++ templates/createOrEdit.html | 50 +++++++++++++++++++++++++++++++++++++++++---- templates/main.html | 12 ++++++++++- urls.py | 10 ++++++--- 6 files changed, 127 insertions(+), 17 deletions(-) diff --git a/polls/models.py b/polls/models.py index acc51d5..f4cf93a 100644 --- a/polls/models.py +++ b/polls/models.py @@ -24,6 +24,12 @@ Models management from django.db import models from django.utils.translation import gettext_lazy as _ +class Category(models.Model): + name = models.CharField(max_length=100) + description = models.TextField() + def __unicode__(self): + return self.name + class PollUser(models.Model): name = models.CharField(max_length=100) email = models.CharField(max_length=100) @@ -34,12 +40,13 @@ class Poll(models.Model): name = models.CharField(max_length=200) description = models.CharField(max_length=1000) author = models.ForeignKey(PollUser) + category = models.ForeignKey(Category, null=True, blank=True) + enddate = models.DateTimeField(null=True, blank=True) base_url = models.CharField(max_length=100) admin_url = models.CharField(max_length=100) modification_date = models.DateTimeField(auto_now=True) - STATUS = (('A', _('Available')), - ('D', _('Disabled')),) - status = models.CharField(max_length=1, choices=STATUS) + public = models.BooleanField(default=False) + open = models.BooleanField(default=True) TYPE = (('P', _('Poll')), ('B', _('Balanced poll')), ('O', _('One choice poll')),) diff --git a/polls/views.py b/polls/views.py index 629caa1..4c6499d 100644 --- a/polls/views.py +++ b/polls/views.py @@ -31,7 +31,7 @@ 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 +from papillon.polls.models import Poll, PollUser, Choice, Voter, Vote, Category def getBaseResponse(request): """Manage basic fields for the template @@ -55,11 +55,23 @@ 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() error = '' if 'bad_poll' in request.GET: response_dct['error'] = _("The poll requested don't exist (anymore?)") return render_to_response('main.html', response_dct) +def category(request, category_id): + "Page for a category" + response_dct, redirect = getBaseResponse(request) + if redirect: + return redirect + category = Category.objects.get(id=int(category_id)) + response_dct['category'] = category + response_dct['polls'] = Poll.objects.filter(public=True, category=category) + return render_to_response('category.html', response_dct) + def createOrEdit(request, admin_url): '''Creation or edition of a poll. admin_url is given to identify a particular poll @@ -103,9 +115,19 @@ def createOrEdit(request, admin_url): author.save() base_url = 'b' + genRandomURL() admin_url = 'a' + genRandomURL() + category = None + if 'poll_category' in request.POST and request.POST['poll_category']: + category = Category.objects.get(id=int(request.POST['poll_category'])) + public = False + if 'poll_public' in request.POST and request.POST['poll_public']: + value = False + if request.POST['poll_public'] == '1': + value = True + public = value poll = Poll(name=request.POST['poll_name'], description=request.POST['poll_desc'], author=author, base_url=base_url, -admin_url=admin_url, status = 'D', type=request.POST['poll_type']) +admin_url=admin_url, type=request.POST['poll_type'], category=category, +public=public) poll.save() url = response_dct['admin_url'] + '/%s/' % poll.admin_url return response_dct, HttpResponseRedirect(url) @@ -126,14 +148,23 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) if 'poll_desc' in request.POST and request.POST['poll_desc']: updated = True poll.description = request.POST['poll_desc'] + if 'poll_open' in request.POST and request.POST['poll_open']: + updated = True + value = False + if request.POST['poll_open'] == '1': + value = True + poll.open = value + if 'poll_public' in request.POST and request.POST['poll_public']: + updated = True + value = False + if request.POST['poll_public'] == '1': + value = True + poll.public = value if updated: poll.save() # base feed of the template - new_dct = {'author_name':poll.author.name, - 'poll_name':poll.name, - 'poll_desc':poll.description, + new_dct = {'poll':poll, 'choices':Choice.objects.filter(poll=poll).order_by('order'), - 'poll_status':poll.status, 'type_name':poll.getTypeLabel()} response_dct.update(new_dct) @@ -180,6 +211,7 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) if redirect: return redirect response_dct['TYPES'] = Poll.TYPE + response_dct['categories'] = Category.objects.all() response_dct['admin_url'] = \ "/".join(request.path.split('/')[:-2]) redirection = None diff --git a/static/styles.css b/static/styles.css index 7359392..8a83a8a 100644 --- a/static/styles.css +++ b/static/styles.css @@ -24,6 +24,10 @@ font-family:arial; background-color:#ced3e1; } +a{ +color:#6f819d; +} + h1, h1 a{ margin:0; margin-top:2px;; @@ -49,6 +53,17 @@ h2 a:hover{ color:grey; } +h3, h3 a{ +color:black; +text-decoration:None; +margin:10px; +font-size:20px; +} + +h3 a:hover{ +color:grey; +} + p{ padding:6px; margin:6px; diff --git a/templates/createOrEdit.html b/templates/createOrEdit.html index 4cc7420..417f7b7 100644 --- a/templates/createOrEdit.html +++ b/templates/createOrEdit.html @@ -9,6 +9,7 @@ {% if error %}

{{ error }}

{% endif %} + {% if not new %} @@ -19,21 +20,59 @@ - {% endif %} + {% endif %} + + - + + - + + - + + + {% if not new %} + + + + {% endif %} + + + + + + + + {% if categories %} + + + + {% endif %} + + {% if choices %} @@ -55,6 +95,7 @@ {% endfor %}{% endif %} + + {% if new %}
http://{{full_base_url}}http://{{full_admin_url}} {% trans "Address to modify the current poll" %}
{% if new %}{% else %}{{author_name}}{% endif %}{% if new %}{% else %}{{poll.author.name}}{% endif %} {% trans "Name, firstname or nickname of the author" %}
{% if new %}{% else %}{% endif %}{% if new %}{% else %}{% endif %} {% trans "Global name to present the poll" %}
{% if new %}{% else %}{% endif %}{% if new %}{% else %}{% endif %} {% trans "Precise description of the poll" %}
+ + {% trans "Status of the poll. When closed no vote add or modification are allowed" %}
+ + {% trans "If the poll is public it is available on the main page" %}
{% if new %} + {%else%}{{poll.category.name}} + {% endif %}{% trans "Category of the poll" %}
{% if new %}
{% trans "Choices" %}{% trans "Label" %}{% trans "Limit" %}{% trans "Delete?"%}
 {%if choice.limit%}{% blocktrans with choice.limit as choice_limit%}Limited to {{choice_limit}} vote(s){% endblocktrans %}{%endif%}
{% if new %} @@ -63,6 +104,7 @@ {% endif %}
diff --git a/templates/main.html b/templates/main.html index 05c8b95..59adba7 100644 --- a/templates/main.html +++ b/templates/main.html @@ -3,7 +3,17 @@ {% block content %} {% if error %}

{{error}}

{%endif%} -

{% trans "Create a poll" %}

+

{%trans "Create a poll"%}

{% trans "Create a new sondage for take a decision, find a date for a meeting, etc." %}

+{% if polls %}

{%trans "Polls"%}

{%endif%} +{% for poll in polls %} +

{{poll.name}} {{poll.description}}

+{% endfor %} + +{% if categories %}

{%trans "Categories"%}

{% endif %} +{% for category in categories %} +

{{category.name}}

+{% endfor %} + {% endblock %} diff --git a/urls.py b/urls.py index 2234ab3..f4e5ec8 100644 --- a/urls.py +++ b/urls.py @@ -18,18 +18,22 @@ # See the file COPYING for details. from django.conf.urls.defaults import * +from django.contrib import admin +admin.autodiscover() + from polls.feeds import PollLatestEntries feeds = { 'poll': PollLatestEntries, } - urlpatterns = patterns('', - (r'^papillon/admin/', include('django.contrib.admin.urls')), + (r'^papillon/admin/(.*)', admin.site.root), (r'^papillon/$', 'papillon.polls.views.index'), (r'^papillon/edit/(?P\w+)/$', - 'papillon.polls.views.createOrEdit'), + 'papillon.polls.views.createOrEdit'), + (r'^papillon/category/(?P\w+)/$', + 'papillon.polls.views.category'), (r'^papillon/poll/(?P\w+)/$', 'papillon.polls.views.poll'), (r'^papillon/poll/(?P\w+)/vote$', 'papillon.polls.views.poll'), (r'^papillon/feeds/(?P.*)$', -- cgit v1.2.3