diff options
-rw-r--r-- | polls/models.py | 13 | ||||
-rw-r--r-- | polls/views.py | 44 | ||||
-rw-r--r-- | static/styles.css | 15 | ||||
-rw-r--r-- | templates/createOrEdit.html | 50 | ||||
-rw-r--r-- | templates/main.html | 12 | ||||
-rw-r--r-- | 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 %}<p class='error'>{{ error }}</p>{% endif %} <table id='new_poll'> <form action="{{admin_url}}" method="post"> + {% if not new %}<tr> <td><label>{% trans "Poll url" %}</label></td> <td colspan='2'><a href='http://{{full_base_url}}'>http://{{full_base_url}}</a></td> @@ -19,21 +20,59 @@ <td colspan='2'><a href='http://{{full_admin_url}}'>http://{{full_admin_url}}</a></td> <td class='form_description'>{% trans "Address to modify the current poll" %}</td> </tr> - {% endif %}<tr> + {% endif %} + + <tr> <td><label for='author_name'>{% trans "Author name" %}</label></td> - <td colspan='2'>{% if new %}<input type='text' name='author_name' value='{{author_name}}'/>{% else %}{{author_name}}{% endif %}</td> + <td colspan='2'>{% if new %}<input type='text' name='author_name' value='{{poll.author.name}}'/>{% else %}{{poll.author.name}}{% endif %}</td> <td class='form_description'>{% trans "Name, firstname or nickname of the author" %}</td> </tr> + <tr> <td><label for='poll_name'>{% trans "Poll name" %}</label></td> - <td colspan='2'>{% if new %}<input type='text' name='poll_name' value='{{poll_name}}'/>{% else %}<input type='text' name='poll_name' value='{{poll_name}}'/>{% endif %}</td> + <td colspan='2'>{% if new %}<input type='text' name='poll_name' value='{{poll.name}}'/>{% else %}<input type='text' name='poll_name' value='{{poll.name}}'/>{% endif %}</td> <td class='form_description'>{% trans "Global name to present the poll" %}</td> </tr> + <tr> <td><label for='poll_desc'>{% trans "Poll description" %}</label></td> - <td colspan='2'>{% if new %}<textarea name='poll_desc'>{{poll_desc}}</textarea>{% else %}<textarea name='poll_desc'>{{poll_desc}}</textarea>{% endif %}</td> + <td colspan='2'>{% if new %}<textarea name='poll_desc'>{{poll.description}}</textarea>{% else %}<textarea name='poll_desc'>{{poll.description}}</textarea>{% endif %}</td> <td class='form_description'>{% trans "Precise description of the poll" %}</td> </tr> + + {% if not new %}<tr> + <td><label for='poll_open'>{% trans "Poll status" %}</label></td> + <td colspan='2'> + <select name='poll_open'> + <option value='1'{%if poll.open %} selected='selected'{%endif%}>{%trans "Open"%}</option> + <option value='0'{%if not poll.open %} selected='selected'{%endif%}>{%trans "Closed"%}</option> + </select> + </td> + <td class='form_description'>{% trans "Status of the poll. When closed no vote add or modification are allowed" %}</td> + </tr>{% endif %} + + <tr> + <td><label for='poll_public'>{% trans "Public" %}</label></td> + <td colspan='2'> + <select name='poll_public'> + <option value='1'{%if poll.public %} selected='selected'{%endif%}>{%trans "Yes"%}</option> + <option value='0'{%if not poll.public %} selected='selected'{%endif%}>{%trans "No"%}</option> + </select> + </td> + <td class='form_description'>{% trans "If the poll is public it is available on the main page" %}</td> + </tr> + + {% if categories %}<tr> + <td><label for='poll_category'>{% trans "Poll category" %}</label></td> + <td colspan='2'>{% if new %} + <select name='poll_category'> + <option value=''>---</option> + {% for category in categories %}<option value='{{category.id}}'>{{category.name}}</option>{% endfor %} + </select>{%else%}{{poll.category.name}} + {% endif %}</td> + <td class='form_description'>{% trans "Category of the poll" %}</td> + </tr>{% endif %} + <tr> <td><label for='poll_type'>{% trans "Poll type" %}</label></td> <td colspan='2'>{% if new %}<select name='poll_type'> @@ -48,6 +87,7 @@ </ul> </td> </tr> + {% if choices %}<tr> <th>{% trans "Choices" %}</th><th>{% trans "Label" %}</th><th>{% trans "Limit" %}</th><th>{% trans "Delete?"%}</th> </tr> @@ -55,6 +95,7 @@ <td> </td><td><input type='text' name='modify_{{choice.id}}' value="{{choice.name}}"/></td><td>{%if choice.limit%}{% blocktrans with choice.limit as choice_limit%}Limited to {{choice_limit}} vote(s){% endblocktrans %}{%endif%}</td><td><input type='checkbox' name='delete_{{choice.id}}'/></td> </tr> {% endfor %}{% endif %} + <tr> <td></td> <td>{% if new %}<input type='hidden' name='new' value='1'/> @@ -63,6 +104,7 @@ <input type='submit' value='{% trans "Edit" %}' /> {% endif %}</td> </tr> + </form> {% if new %} </table> 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 %}<p class='error'>{{error}}</p>{%endif%} -<h2><a href='edit/0'>{% trans "Create a poll" %}</a></h2> +<h2><a href='edit/0'>{%trans "Create a poll"%}</a></h2> <p>{% trans "Create a new sondage for take a decision, find a date for a meeting, etc." %}</p> +{% if polls %}<h2>{%trans "Polls"%}</h2>{%endif%} +{% for poll in polls %} +<p><a href='poll/{{poll.base_url}}'>{{poll.name}}</a> {{poll.description}}</p> +{% endfor %} + +{% if categories %}<h2>{%trans "Categories"%}</h2>{% endif %} +{% for category in categories %} +<h3><a href='category/{{category.id}}'>{{category.name}}</a></h3> +{% endfor %} + {% endblock %} @@ -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<admin_url>\w+)/$', - 'papillon.polls.views.createOrEdit'), + 'papillon.polls.views.createOrEdit'), + (r'^papillon/category/(?P<category_id>\w+)/$', + 'papillon.polls.views.category'), (r'^papillon/poll/(?P<poll_url>\w+)/$', 'papillon.polls.views.poll'), (r'^papillon/poll/(?P<poll_url>\w+)/vote$', 'papillon.polls.views.poll'), (r'^papillon/feeds/(?P<url>.*)$', |