From f24cc7c0c181c58eb36ec25fab570368a478b820 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 00:42:37 +0200 Subject: [PATCH 1/6] Minor fixes --- openslides/poll/views.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/openslides/poll/views.py b/openslides/poll/views.py index 43b724c05..4211a8eb6 100644 --- a/openslides/poll/views.py +++ b/openslides/poll/views.py @@ -74,17 +74,10 @@ def view(request, poll_id): }, prefix="o%d" % option.id) if request.method == 'POST' and success == options.count(): messages.success(request, _("Votes are successfully saved.") ) - - if poll.application: - app = 'application/base_application.html' - elif poll.assignment: - app = 'assignment/base_assignment.html' - else: - app = 'poll/base_poll.html' + return { 'poll': poll, 'options': options, - 'app': app, } @@ -92,7 +85,7 @@ def view(request, poll_id): @template('poll/edit.html') def edit(request, poll_id=None): """ - View zum editieren und neuanlegen von Wahlen + View to create and edit a poll object. """ if poll_id is not None: poll = Poll.objects.get(id=poll_id) @@ -118,14 +111,9 @@ def edit(request, poll_id=None): form = PollForm() else: form = PollForm(instance=poll) - try: - options = poll.option_set.all() - except AttributeError: - options = [] return { 'form': form, 'poll': poll, - 'options': options, } @@ -144,7 +132,7 @@ def delete(request, poll_id): @template('poll/option_edit.html') def option_edit(request, poll_id=None, option_id=None): """ - View zum editieren und neuanlegen von Optionen für eine Wahl + View to create and edit options of a poll object. """ if option_id is not None: option = Option.objects.get(id=option_id) @@ -170,7 +158,7 @@ def option_edit(request, poll_id=None, option_id=None): if poll_id is None: form = OptionForm() else: - poll = poll = Poll.objects.get(id=poll_id) + poll = Poll.objects.get(id=poll_id) form = OptionForm(initial={'poll': poll}) else: form = OptionForm(instance=option) From 2278ddca5408d25d57dae329b71fca7cb599d3f6 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 00:43:09 +0200 Subject: [PATCH 2/6] DB change: Changed voteinvalid to votesinvalid. --- openslides/application/views.py | 4 ++-- openslides/assignment/templates/assignment/poll_view.html | 2 +- openslides/assignment/views.py | 4 ++-- openslides/poll/models.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openslides/application/views.py b/openslides/application/views.py index 680da866c..14fdb57cd 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -323,7 +323,7 @@ def view_poll(request, poll_id): if request.method == 'POST': form = PollInvalidForm(request.POST, prefix="poll") if form.is_valid(): - poll.voteinvalid = form.cleaned_data['invalid'] or 0 + poll.votesinvalid = form.cleaned_data['invalid'] or 0 poll.save() for option in options: @@ -336,7 +336,7 @@ def view_poll(request, poll_id): cleaned_data['undesided'] or 0 option.save() else: - form = PollInvalidForm(initial={'invalid': poll.voteinvalid}, prefix="poll") + form = PollInvalidForm(initial={'invalid': poll.votesinvalid}, prefix="poll") for option in options: option.form = OptionResultForm(initial={ 'yes': option.voteyes, diff --git a/openslides/assignment/templates/assignment/poll_view.html b/openslides/assignment/templates/assignment/poll_view.html index 111a1b81d..9ddde0f45 100644 --- a/openslides/assignment/templates/assignment/poll_view.html +++ b/openslides/assignment/templates/assignment/poll_view.html @@ -33,7 +33,7 @@ {% endfor %} - + {{ form.invalid.errors }}{{ form.invalid }} {% if perms.poll.can_manage_poll %} diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index f441c42e0..ff0891dd7 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -199,7 +199,7 @@ def poll_view(request, poll_id, ballotnumber=1): if request.method == 'POST': form = PollInvalidForm(request.POST, prefix="poll") if form.is_valid(): - poll.voteinvalid = form.cleaned_data['invalid'] or 0 + poll.votesinvalid = form.cleaned_data['invalid'] or 0 poll.save() success = 0 @@ -214,7 +214,7 @@ def poll_view(request, poll_id, ballotnumber=1): if success == options.count(): messages.success(request, _("Votes are successfully saved.") ) else: - form = PollInvalidForm(initial={'invalid': poll.voteinvalid}, prefix="poll") + form = PollInvalidForm(initial={'invalid': poll.votesinvalid}, prefix="poll") for option in options: option.form = OptionResultForm(initial={ 'yes': option.voteyes, diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 223f5bc26..05e11cf3b 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -26,7 +26,7 @@ class Poll(models.Model): assignment = models.ForeignKey(Assignment, null=True, blank=True, verbose_name = _("Election")) description = models.TextField(null=True, blank=True, verbose_name = _("Description")) votescast = models.IntegerField(null=True, blank=True, verbose_name = _("Votes cast")) - voteinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid")) + votesinvalid = models.IntegerField(null=True, blank=True, verbose_name = _("Votes invalid")) def add_option(self, option): self.save() From ed4097740318e2cf6e880e6f18623a7cc739f0cf Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 01:24:50 +0200 Subject: [PATCH 3/6] Removed reduced agenda pdf. Not useable. --- .../agenda/templates/agenda/overview.html | 3 +-- openslides/agenda/urls.py | 3 --- openslides/utils/pdf.py | 24 ++++--------------- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/openslides/agenda/templates/agenda/overview.html b/openslides/agenda/templates/agenda/overview.html index 99b900d08..f7f8ccc13 100644 --- a/openslides/agenda/templates/agenda/overview.html +++ b/openslides/agenda/templates/agenda/overview.html @@ -71,8 +71,7 @@ {% if perms.agenda.can_manage_agenda %} {% endif %} - - + {% for item in items %} {% if not item.hidden or perms.agenda.can_manage_agenda %} diff --git a/openslides/agenda/urls.py b/openslides/agenda/urls.py index 4fd64dc0d..273847250 100644 --- a/openslides/agenda/urls.py +++ b/openslides/agenda/urls.py @@ -54,9 +54,6 @@ urlpatterns = patterns('agenda.views', url(r'^item/(?P\d+)/del/$', 'delete', name='item_delete'), - url(r'^item/print/(?P\d+)/$', 'print_agenda', - name='print_agenda_full'), - url(r'^item/print/$', 'print_agenda', name='print_agenda'), ) diff --git a/openslides/utils/pdf.py b/openslides/utils/pdf.py index 34bd37e50..ac1058e24 100755 --- a/openslides/utils/pdf.py +++ b/openslides/utils/pdf.py @@ -182,11 +182,6 @@ def firstPage(canvas, doc): canvas.setFillGray(0) #canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, doc.title) canvas.drawString(2.75*cm, PAGE_HEIGHT-108, doc.title) - if doc.subtitle: - canvas.setFont('Ubuntu',10) - canvas.setFillGray(0.4) - #canvas.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-125, doc.subtitle) - canvas.drawString(2.75*cm, PAGE_HEIGHT-125, doc.subtitle) # footer (with page number) canvas.setFont('Ubuntu',8) canvas.setFillGray(0.4) @@ -201,7 +196,7 @@ def laterPages(canvas, doc): canvas.drawString(10*cm, 1*cm, _("Page")+" %s" % doc.page) canvas.restoreState() -def print_agenda(request, printAllItems=None): +def print_agenda(request): response = HttpResponse(mimetype='application/pdf') filename = u'filename=%s.pdf;' % _("Agenda") response['Content-Disposition'] = filename.encode('utf-8') @@ -209,25 +204,16 @@ def print_agenda(request, printAllItems=None): story = [Spacer(1,3*cm)] doc.title = _("Agenda") - if printAllItems: - doc.subtitle = "("+_("full")+")" - else: - doc.subtitle = "("+_("abridged")+")" # print item list items = children_list(Item.objects.filter(parent=None).order_by('weight')) for item in items: if item.hidden is False: # print all items - if printAllItems: - if item.parents: - story.append(Paragraph(item.title, stylesheet['Subitem'])) - else: - story.append(Paragraph(item.title, stylesheet['Item'])) - # print items without parents only + if item.parents: + story.append(Paragraph(item.title, stylesheet['Subitem'])) else: - if item.parent is None: - story.append(Paragraph(item.title, stylesheet['Subitem'])) + story.append(Paragraph(item.title, stylesheet['Item'])) doc.build(story, onFirstPage=firstPage, onLaterPages=laterPages) return response @@ -240,7 +226,6 @@ def print_userlist(request): story = [Spacer(1,2*cm)] doc.title = _("List of Participants") - doc.subtitle = "" # Table data= [['#', _('Last Name'), _('First Name'), _('Group'), _('Type'), _('Committee')]] sort = 'last_name' @@ -303,7 +288,6 @@ def print_application(request, application_id=None): response['Content-Disposition'] = filename.encode('utf-8') doc = SimpleDocTemplate(response) doc.title = None - doc.subtitle = None story = [Spacer(1,2*cm)] if application_id is None: #print all applications From e752e05b0fd069b3b747eac9a23962983147cec7 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 01:40:06 +0200 Subject: [PATCH 4/6] Removed unnecessary parts from poll system. Needs new development in future. --- openslides/poll/templates/poll/base_poll.html | 13 -- openslides/poll/templates/poll/edit.html | 48 ----- .../poll/templates/poll/option_edit.html | 23 --- openslides/poll/templates/poll/overview.html | 30 --- openslides/poll/templates/poll/view.html | 63 ------ openslides/poll/urls.py | 26 --- openslides/poll/views.py | 179 ------------------ openslides/templates/base.html | 4 - openslides/urls.py | 1 - 9 files changed, 387 deletions(-) delete mode 100644 openslides/poll/templates/poll/base_poll.html delete mode 100644 openslides/poll/templates/poll/edit.html delete mode 100644 openslides/poll/templates/poll/option_edit.html delete mode 100644 openslides/poll/templates/poll/overview.html delete mode 100644 openslides/poll/templates/poll/view.html delete mode 100644 openslides/poll/urls.py delete mode 100644 openslides/poll/views.py diff --git a/openslides/poll/templates/poll/base_poll.html b/openslides/poll/templates/poll/base_poll.html deleted file mode 100644 index 2619ccce4..000000000 --- a/openslides/poll/templates/poll/base_poll.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "base.html" %} -{% load tags %} - -{% block submenu %} - {% url poll_overview as url_polloverview %} -

{%trans "Polls" %}

- -{% endblock %} diff --git a/openslides/poll/templates/poll/edit.html b/openslides/poll/templates/poll/edit.html deleted file mode 100644 index 80a71d1a6..000000000 --- a/openslides/poll/templates/poll/edit.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends "poll/base_poll.html" %} -{% block title %}{{ block.super }} - {%trans "Poll" %}{% endblock %} - -{% block content %} - {% if poll %} -

{%trans "Edit poll" %}

- {% else %} -

{%trans "New poll" %}

- {% endif %} - -
{% csrf_token %} - {{ form.as_p }} - - - - - - - {% if poll %} -

{%trans "Options" %}

- - - - - - {% for option in options %} - - - - - {% endfor %} -
{%trans "Option" %}{%trans "Actions" %}
{{ option }} - -
-
- - - - {% endif %} -
- -{% endblock %} diff --git a/openslides/poll/templates/poll/option_edit.html b/openslides/poll/templates/poll/option_edit.html deleted file mode 100644 index 68b6e5de5..000000000 --- a/openslides/poll/templates/poll/option_edit.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "poll/base_poll.html" %} -{% block title %}{{ block.super }} - {%trans "Poll" %}{% endblock %} - -{% block content %} - {% if option %} -

{%trans "Edit Poll Option" %}

- {% else %} -

{%trans "New Poll Option" %}

- {% endif %} - -
{% csrf_token %} - {{ form.as_p }} - - - - - -
-{% endblock %} diff --git a/openslides/poll/templates/poll/overview.html b/openslides/poll/templates/poll/overview.html deleted file mode 100644 index d6623c79d..000000000 --- a/openslides/poll/templates/poll/overview.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "poll/base_poll.html" %} -{% block title %}{{ block.super }} - {%trans "Polls" %}{% endblock %} - -{% block content %} -

{%trans "Polls" %}

- - - - - {% if perms.poll.can_manage_poll %} - - {% endif %} - - {% for poll in polls %} - - - - {% if perms.poll.can_manage_poll %} - - {% endif %} - - {% empty %} - - - - {% endfor %} -
{%trans "Polls" %}{%trans "Options" %}{%trans "Actions" %}
{{ poll }}{{ poll.get_options|length }} - -
{%trans "No polls available." %}
-{% endblock %} diff --git a/openslides/poll/templates/poll/view.html b/openslides/poll/templates/poll/view.html deleted file mode 100644 index 2ce505b36..000000000 --- a/openslides/poll/templates/poll/view.html +++ /dev/null @@ -1,63 +0,0 @@ -{% extends app %} -{% block title %}{{ block.super }} - {%trans "Poll" %} "{{ poll.title }}"{% endblock %} - -{% block content %} -

{{ poll.title }}

-

{{ poll.description }}

-
{% csrf_token %} - - - - {% if poll.optiondecision %} - - - - {% else %} - - {% endif %} - {% if perms.poll.can_manage_poll %} - - {% endif %} - - {% for option in options %} - - - {% if poll.optiondecision %} - - - - {% else %} - - {% endif %} - {% if perms.poll.can_manage_poll %} - - {% endif %} - - {% endfor %} -
{%trans "Option" %}{%trans "Yes" %}{%trans "No" %}{%trans "Abstention" %}{%trans "Votes" %}{% trans "Actions" %}
{{ option }}{{ option.form.yes.errors }}{{ option.form.yes }}{{ option.form.no.errors }}{{ option.form.no }}{{ option.form.undesided.errors }}{{ option.form.undesided }}{{ option.form.yes.errors }}{{ option.form.yes }}
- - {% if perms.poll.can_manage_poll %} -

- - - {% if not poll.application and not poll.assignment %} - - - - {% endif %} - - -

- {% endif %} -
- -{% endblock %} diff --git a/openslides/poll/urls.py b/openslides/poll/urls.py deleted file mode 100644 index e0c6c5bfd..000000000 --- a/openslides/poll/urls.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - openslides.poll.urls - ~~~~~~~~~~~~~~~~~~~~ - - URL list for the poll app. - - :copyright: 2011 by the OpenSlides team, see AUTHORS. - :license: GNU GPL, see LICENSE for more details. -""" - -from django.conf.urls.defaults import * - -urlpatterns = patterns('poll.views', - url(r'^poll/$', 'get_overview', name='poll_overview'), - url(r'^poll/(?P\d+)$', 'view', name='poll_view'), - url(r'^poll/new$', 'edit', name='poll_new'), - url(r'^poll/(?P\d+)/edit$', 'edit', name='poll_edit'), - url(r'^poll/(?P\d+)/del$', 'delete', name='poll_delete'), - url(r'^poll/option/new$', 'option_edit', name='option_new'), - url(r'^poll/(?P\d+)/option/new$', 'option_edit', name='option_new_fixpoll'), - url(r'^poll/option/(?P\d+)/edit$', 'option_edit', name='option_edit'), - url(r'^poll/option/(?P\d+)/del$', 'option_delete', name='option_delete'), - # url(r'^poll/pdf/(?P\d+)$', 'print_poll', name='poll_print'), -) diff --git a/openslides/poll/views.py b/openslides/poll/views.py deleted file mode 100644 index 4211a8eb6..000000000 --- a/openslides/poll/views.py +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - openslides.poll.views - ~~~~~~~~~~~~~~~~~~~~~ - - Views for the poll app. - - :copyright: 2011 by the OpenSlides team, see AUTHORS. - :license: GNU GPL, see LICENSE for more details. -""" - -from django.shortcuts import render_to_response, redirect -from django.template import RequestContext -from django.core.urlresolvers import reverse -from django.contrib import messages -from django.utils.translation import ugettext as _ - -from poll.models import Poll, Option -from poll.forms import PollForm, OptionForm, OptionResultForm -from utils.utils import template, permission_required, gen_confirm_form -#from utils.pdf import print_poll - - -@permission_required('poll.can_view_poll') -@template('poll/overview.html') -def get_overview(request): - query = Poll.objects.filter(assignment=None).filter(application=None) - try: - sort = request.GET['sort'] - if sort in ['title']: - query = query.order_by(sort) - except KeyError: - pass - if 'reverse' in request.GET: - query = query.reverse() - - polls = query.all() - return { - 'polls': polls, - } - - -@template('poll/view.html') -@permission_required('poll.can_view_poll') -def view(request, poll_id): - poll = Poll.objects.get(pk=poll_id) - if poll.application and not request.path.startswith('/application'): - return redirect(reverse('application_poll_view', args=[poll_id])) - if poll.assignment and not request.path.startswith('/assignment'): - return redirect(reverse('assignment_poll_view', args=[poll_id, 0])) - if not (poll.application or poll.assignment) and not request.path.startswith('/poll'): - return redirect(reverse('poll_view', args=[poll_id])) - - options = poll.option_set.all() - if request.user.has_perm('poll.can_manage_poll'): - success = 0 - for option in options: - if request.method == 'POST': - option.form = OptionResultForm(request.POST, prefix="o%d" % option.id) - if option.form.is_valid(): - option.voteyes = option.form.cleaned_data['yes'] - option.voteno = option.form.cleaned_data['no'] or 0 - option.voteundesided = option.form.cleaned_data['undesided'] or 0 - option.save() - success = success + 1 - else: - messages.error(request, _('Please check the form for errors.')) - else: - option.form = OptionResultForm(initial={ - 'yes': option.voteyes, - 'no': option.voteno, - 'undesided': option.voteundesided, - }, prefix="o%d" % option.id) - if request.method == 'POST' and success == options.count(): - messages.success(request, _("Votes are successfully saved.") ) - - return { - 'poll': poll, - 'options': options, - } - - -@permission_required('poll.can_manage_poll') -@template('poll/edit.html') -def edit(request, poll_id=None): - """ - View to create and edit a poll object. - """ - if poll_id is not None: - poll = Poll.objects.get(id=poll_id) - else: - poll = None - - if request.method == 'POST': - if poll_id is None: - form = PollForm(request.POST) - else: - form = PollForm(request.POST, instance=poll) - - if form.is_valid(): - poll = form.save() - if poll_id is None: - messages.success(request, _('New poll was successfully created.')) - else: - messages.success(request, _('Poll was successfully modified.')) - return redirect(reverse("poll_overview")) - messages.error(request, _('Please check the form for errors.')) - else: - if poll_id is None: - form = PollForm() - else: - form = PollForm(instance=poll) - return { - 'form': form, - 'poll': poll, - } - - -@permission_required('poll.can_manage_poll') -def delete(request, poll_id): - poll = Poll.objects.get(id=poll_id) - if request.method == 'POST': - poll.delete() - messages.success(request, _('Poll %s was successfully deleted.') % poll) - else: - gen_confirm_form(request, _('Do you really want to delete %s?') % poll, reverse('poll_delete', args=[poll_id])) - return redirect(reverse('poll_overview')) - - -@permission_required('poll.can_manage_poll') -@template('poll/option_edit.html') -def option_edit(request, poll_id=None, option_id=None): - """ - View to create and edit options of a poll object. - """ - if option_id is not None: - option = Option.objects.get(id=option_id) - else: - option = None - - if request.method == 'POST': - if option_id is None: - form = OptionForm(request.POST) - else: - form = OptionForm(request.POST, instance=option) - - if form.is_valid(): - option = form.save() - if option_id is None: - messages.success(request, _('New option was successfully created.')) - else: - messages.success(request, _('Option was successfully modified.')) - return redirect(reverse("poll_overview")) - messages.error(request, _('Please check the form for errors.')) - else: - if option_id is None: - if poll_id is None: - form = OptionForm() - else: - poll = Poll.objects.get(id=poll_id) - form = OptionForm(initial={'poll': poll}) - else: - form = OptionForm(instance=option) - return { - 'form': form, - 'option': option, - } - - -@permission_required('poll.can_manage_poll') -def option_delete(request, option_id): - option = Option.objects.get(id=option_id) - if request.method == 'POST': - option.delete() - messages.success(request, _('Option %s was successfully deleted.') % option) - else: - gen_confirm_form(request, _('Do you really want to delete the option %s?') % option_id, reverse('option_delete', args=[option_id])) - return redirect(reverse('poll_overview')) diff --git a/openslides/templates/base.html b/openslides/templates/base.html index e76cc8f3d..6fb26b447 100644 --- a/openslides/templates/base.html +++ b/openslides/templates/base.html @@ -55,10 +55,6 @@
  • {%trans "Elections" %}
  • {% endif %} - {% if perms.poll.can_view_poll or perms.poll.can_manage_poll %} -
  • - {%trans "Polls" %}
  • - {% endif %} {% if perms.participant.can_view_participants or perms.participant.can_manage_participants %}
  • {%trans "Participants" %}
  • diff --git a/openslides/urls.py b/openslides/urls.py index 7da6d1a0f..ee6cb8130 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -21,7 +21,6 @@ urlpatterns = patterns('', (r'', include('openslides.agenda.urls')), (r'', include('openslides.application.urls')), (r'', include('openslides.participant.urls')), - (r'', include('openslides.poll.urls')), (r'', include('openslides.assignment.urls')), (r'', include('openslides.system.urls')), (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), From b1b5d9cb704e1797c937b41bf6b1008df239f242 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 01:46:56 +0200 Subject: [PATCH 5/6] Removed old poll permissions. --- openslides/poll/models.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 05e11cf3b..77ba945cf 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -78,12 +78,6 @@ class Poll(models.Model): def __unicode__(self): return self.title - class Meta: - permissions = ( - ('can_view_poll', "Can view polls"), - ('can_manage_poll', "Can manage polls"), - ) - class Option(models.Model): text = models.CharField(max_length=100, null=True, blank=True, verbose_name = _("Text")) From ca0c50caef52cb9ef73b76933442f10e2d84405e Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Sat, 3 Sep 2011 10:52:29 +0200 Subject: [PATCH 6/6] Many improvements for application and assignment poll system. --- .../templates/beamer/ItemAssignment.html | 2 +- openslides/application/models.py | 10 ++---- .../templates/application/poll_view.html | 14 ++++----- .../templates/application/view.html | 8 ++--- openslides/application/views.py | 2 ++ openslides/assignment/forms.py | 4 +-- openslides/assignment/models.py | 5 ++- .../templates/assignment/overview.html | 2 +- .../templates/assignment/poll_view.html | 6 ++-- .../assignment/templates/assignment/view.html | 12 +++---- openslides/assignment/urls.py | 6 ++-- openslides/assignment/views.py | 17 +++++----- openslides/poll/models.py | 31 +++++++++++++++++-- openslides/utils/pdf.py | 23 ++++++-------- 14 files changed, 77 insertions(+), 65 deletions(-) diff --git a/openslides/agenda/templates/beamer/ItemAssignment.html b/openslides/agenda/templates/beamer/ItemAssignment.html index 51ee567bc..98157b4c7 100644 --- a/openslides/agenda/templates/beamer/ItemAssignment.html +++ b/openslides/agenda/templates/beamer/ItemAssignment.html @@ -10,7 +10,7 @@

    {% trans "Status" %}:

    {% trans item.assignment.get_status_display %}

    {% trans "Number of available posts" %}:

    - {{ item.assignment.assignment_number }} + {{ item.assignment.posts }} {% endif %} diff --git a/openslides/application/models.py b/openslides/application/models.py index 470e0d065..5158fcf3f 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -351,14 +351,8 @@ class Application(models.Model): Generates a poll object for the application """ from poll.models import Poll - if pollcount > 1: - description = _("%s. poll") % pollcount - else: - description = _("Poll") - poll = Poll(title=_("Application #%s") % self.number, \ - optiondecision=True, \ - application=self, - description=description) + poll = Poll(optiondecision=True, \ + application=self) poll.save() poll.add_option(self) self.writelog(_("Poll created"), user) diff --git a/openslides/application/templates/application/poll_view.html b/openslides/application/templates/application/poll_view.html index a02f6fc11..37e13cd1f 100644 --- a/openslides/application/templates/application/poll_view.html +++ b/openslides/application/templates/application/poll_view.html @@ -1,25 +1,25 @@ {% extends 'application/base_application.html' %} -{% block title %}{{ block.super }} - {{ poll.title }}{% endblock %} +{% block title %}{{ block.super }} - {{ poll }}{% endblock %} -{% if perms.poll.can_manage_poll %} +{% if perms.application.can_manage_application %} {% block submenu %} {{ block.super }}
    -

    {%trans "Application" %} #{{poll.application.number}}

    +

    {%trans "Application" %} #{{ poll.application.number }}

    {% endblock %} {% endif %} {% block content %} -

    {{ poll.title }}

    -

    Title: "{{ poll.application.title }}"

    +

    {%trans "Application" %} #{{ poll.application.number }} - {%trans "Vote" %}

    +

    {{ poll.application.title }}

    {% if perms.poll.can_manage_poll %}
    {% csrf_token %}
    - {{ poll.description }} + {%trans "Results" %}: {{ ballot }}. {%trans "Vote" %}

    {{ options.0.form.yes.errors }}{{ options.0.form.yes }}

    diff --git a/openslides/application/templates/application/view.html b/openslides/application/templates/application/view.html index b08999374..7ec8742df 100644 --- a/openslides/application/templates/application/view.html +++ b/openslides/application/templates/application/view.html @@ -149,7 +149,7 @@ {% endif %} {% endif %} {% else %} - {% trans "Enter vote result!" %} + {% trans "Enter vote results!" %} {% endif %} {% if not forloop.last %}
    {% endif %} {% empty %} @@ -206,13 +206,13 @@
    -

    {% trans "Application" %} +

    {% trans "Application" %} {% if application.number != None %} #{{ application.number }} {% else %} [no number] - {% endif %}

    -

    {{ application.title }}

    + {% endif %} +

    {{ application.title }}

    {{ application.text|linebreaks }} diff --git a/openslides/application/views.py b/openslides/application/views.py index 14fdb57cd..69c098618 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -318,6 +318,7 @@ def view_poll(request, poll_id): view a poll for this application. """ poll = Poll.objects.get(pk=poll_id) + ballot = poll.ballot options = poll.options if request.user.has_perm('application.can_manage_applications'): if request.method == 'POST': @@ -347,4 +348,5 @@ def view_poll(request, poll_id): 'poll': poll, 'form': form, 'options': options, + 'ballot': ballot, } diff --git a/openslides/assignment/forms.py b/openslides/assignment/forms.py index 0a8ee9ad5..afb42153b 100644 --- a/openslides/assignment/forms.py +++ b/openslides/assignment/forms.py @@ -17,7 +17,7 @@ from participant.models import Profile from assignment.models import Assignment -class AssigmentForm(ModelForm): +class AssignmentForm(ModelForm): error_css_class = 'error' required_css_class = 'required' @@ -26,7 +26,7 @@ class AssigmentForm(ModelForm): exclude = ('status', 'profile') -class AssigmentRunForm(Form): +class AssignmentRunForm(Form): error_css_class = 'error' candidate = ModelChoiceField( diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 50b1f7652..6596ce5d3 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -25,7 +25,7 @@ class Assignment(models.Model): name = models.CharField(max_length=100, verbose_name = _("Name")) description = models.TextField(null=True, blank=True, verbose_name = _("Description")) - assignment_number = models.PositiveSmallIntegerField(verbose_name = _("Number of available posts")) + posts = models.PositiveSmallIntegerField(verbose_name = _("Number of available posts")) polldescription = models.CharField(max_length=50, null=True, blank=True, verbose_name = _("Short description (for ballot paper)")) profile = models.ManyToManyField(Profile, null=True, blank=True) status = models.CharField(max_length=1, choices=STATUS, default='sea') @@ -69,10 +69,9 @@ class Assignment(models.Model): def gen_poll(self): from poll.models import Poll poll = Poll() - poll.title = _("Election for %s") % self.name # Option A: candidates <= available posts -> yes/no/abstention - if self.profile.count() <= self.assignment_number: + if self.profile.count() <= self.posts: poll.optiondecision = True else: poll.optiondecision = False diff --git a/openslides/assignment/templates/assignment/overview.html b/openslides/assignment/templates/assignment/overview.html index cb1a1cdf6..65c2b61aa 100644 --- a/openslides/assignment/templates/assignment/overview.html +++ b/openslides/assignment/templates/assignment/overview.html @@ -27,7 +27,7 @@ {% for assignment in assignments %} {{ assignment }} - {{ assignment.profile.count }} / {{ assignment.assignment_number }} + {{ assignment.profile.count }} / {{ assignment.posts }} {{ assignment.get_status_display }} {% if perms.assignment.can_manage_assignment %} diff --git a/openslides/assignment/templates/assignment/poll_view.html b/openslides/assignment/templates/assignment/poll_view.html index 9ddde0f45..e2c3d47b2 100644 --- a/openslides/assignment/templates/assignment/poll_view.html +++ b/openslides/assignment/templates/assignment/poll_view.html @@ -1,8 +1,8 @@ {% extends 'assignment/base_assignment.html' %} -{% block title %}{{ block.super }} - {%trans "Poll" %} "{{ poll.title }}"{% endblock %} +{% block title %}{{ block.super }} - {%trans "Poll" %} "{{ poll }}"{% endblock %} {% block content %} -

    {{ poll.title }}

    +

    {{ poll }}

    {{ ballotnumber }}. {%trans "ballot" %}: {{options.count}} {% blocktrans count counter=options|length %}candidate{% plural %}candidates{% endblocktrans %}

    @@ -46,7 +46,7 @@ {%trans 'Back to election' %} - + diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html index bafefc227..b8684ed1f 100644 --- a/openslides/assignment/templates/assignment/view.html +++ b/openslides/assignment/templates/assignment/view.html @@ -9,7 +9,7 @@ {% trans assignment.get_status_display %}

    {% trans "Number of available posts" %}:

    - {{ assignment.assignment_number }} + {{ assignment.posts }}


    @@ -122,7 +122,7 @@ {% trans "Candidates" %} {% for poll in assignment.poll_set.all %} - {% if perms.assignment.can_manage_assignment %}
    {% endif %} + {% if perms.assignment.can_manage_assignment %}{% endif %} {{forloop.counter}}. {% if perms.assignment.can_manage_assignment %} @@ -132,13 +132,11 @@ {% endfor %} {% if assignment.profile.count > 0 and perms.assignment.can_manage_assignment and assignment.status == "vot" %} - {% with ballotnumber=assignment.poll_set.all.count %} - + - {% endwith %} {% endif %} @@ -169,13 +167,11 @@ {% trans "No ballots available." %} {% if assignment.profile.count > 0 and perms.assignment.can_manage_assignment and assignment.status == "vot" %} - {% with ballotnumber=assignment.poll_set.all.count %} -

    +

    - {% endwith %} {% endif %} {% endif %} diff --git a/openslides/assignment/urls.py b/openslides/assignment/urls.py index 22ca6a5fc..dae4f63e4 100644 --- a/openslides/assignment/urls.py +++ b/openslides/assignment/urls.py @@ -40,13 +40,13 @@ urlpatterns = patterns('assignment.views', url(r'^assignment/(?P\d+)/delother/(?P\d+)$', 'delother', \ name='assignment_delother'), - url(r'^assignment/poll/(?P\d+)/print/(?P\d+)/(?P\d+)$', 'print_assignment_poll', \ + url(r'^assignment/poll/(?P\d+)/print$', 'print_assignment_poll', \ name='print_assignment_poll'), - url(r'^assignment/(?P\d+)/gen_poll/(?P\d+)$', 'gen_poll', \ + url(r'^assignment/(?P\d+)/gen_poll$', 'gen_poll', \ name='assignment_gen_poll'), - url(r'^assignment/poll/(?P\d+)/(?P\d+)$', 'poll_view', \ + url(r'^assignment/poll/(?P\d+)$', 'poll_view', \ name='assignment_poll_view'), url(r'^assignment/poll/(?P\d+)/del$', 'delete_poll', \ diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index ff0891dd7..774d7e9f0 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -19,7 +19,7 @@ from django.utils.translation import ugettext as _ from poll.models import Poll, Option from poll.forms import OptionResultForm, PollInvalidForm from assignment.models import Assignment -from assignment.forms import AssigmentForm, AssigmentRunForm +from assignment.forms import AssignmentForm, AssignmentRunForm from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form from utils.pdf import print_assignment_poll from participant.models import Profile @@ -53,7 +53,7 @@ def view(request, assignment_id=None): assignment = Assignment.objects.get(pk=assignment_id) if request.method == 'POST': if request.user.has_perm('assignment.can_nominate_other'): - form = AssigmentRunForm(request.POST) + form = AssignmentRunForm(request.POST) if form.is_valid(): user = form.cleaned_data['candidate'] try: @@ -63,7 +63,7 @@ def view(request, assignment_id=None): messages.error(request, e) else: if request.user.has_perm('assignment.can_nominate_other'): - form = AssigmentRunForm() + form = AssignmentRunForm() # list of candidates candidates = set() @@ -102,7 +102,7 @@ def edit(request, assignment_id=None): assignment = None if request.method == 'POST': - form = AssigmentForm(request.POST, instance=assignment) + form = AssignmentForm(request.POST, instance=assignment) if form.is_valid(): form.save() if assignment_id is None: @@ -111,7 +111,7 @@ def edit(request, assignment_id=None): messages.success(request, _('Election was successfully modified.')) return redirect(reverse("assignment_overview")) else: - form = AssigmentForm(instance=assignment) + form = AssignmentForm(instance=assignment) return { 'form': form, 'assignment': assignment, @@ -180,19 +180,20 @@ def delother(request, assignment_id, profile_id): @permission_required('assignment.can_manage_assignment') -def gen_poll(request, assignment_id, ballotnumber): +def gen_poll(request, assignment_id): try: poll = Assignment.objects.get(pk=assignment_id).gen_poll() messages.success(request, _("New ballot was successfully created.") ) except Assignment.DoesNotExist: pass - return redirect(reverse('assignment_poll_view', args=[poll.id, ballotnumber])) + return redirect(reverse('assignment_poll_view', args=[poll.id])) @permission_required('assignment.can_view_assignment') @template('assignment/poll_view.html') -def poll_view(request, poll_id, ballotnumber=1): +def poll_view(request, poll_id): poll = Poll.objects.get(pk=poll_id) + ballotnumber = poll.ballot options = poll.options.order_by('user__user__first_name') assignment = poll.assignment if request.user.has_perm('assignment.can_manage_assignment'): diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 77ba945cf..90047355f 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -19,8 +19,6 @@ from participant.models import Profile class Poll(models.Model): - #TODO: Mehrheit in den Zahlen festmachen - title = models.CharField(max_length=100, verbose_name = _("Title")) optiondecision = models.BooleanField(default=True, verbose_name = _("Poll of decision (yes, no, abstention)")) application = models.ForeignKey(Application, null=True, blank=True, verbose_name = _("Application")) assignment = models.ForeignKey(Assignment, null=True, blank=True, verbose_name = _("Election")) @@ -58,6 +56,30 @@ class Poll(models.Model): def options_values(self): return [option.value for option in self.options] + @property + def count_ballots(self): + if self.application: + return Poll.objects.filter(application=self.application).count() + if self.assignment: + return Poll.objects.filter(assignment=self.assignment).count() + return None + + @property + def ballot(self): + if self.application: + counter = 0 + for poll in Poll.objects.filter(application=self.application): + counter = counter + 1 + if self == poll: + return counter + if self.assignment: + counter = 0 + for poll in Poll.objects.filter(assignment=self.assignment): + counter = counter + 1 + if self == poll: + return counter + return None + @models.permalink def get_absolute_url(self, link='view'): if self.application: @@ -76,7 +98,10 @@ class Poll(models.Model): return ('poll_delete', [str(self.id)]) def __unicode__(self): - return self.title + if self.application: + return self.application.title + if self.assignment: + return self.assignment.name class Option(models.Model): diff --git a/openslides/utils/pdf.py b/openslides/utils/pdf.py index ac1058e24..ac73c31f8 100755 --- a/openslides/utils/pdf.py +++ b/openslides/utils/pdf.py @@ -320,10 +320,10 @@ def print_application_poll(request, poll_id=None): circle = "  " cell = [] cell.append(Spacer(0,0.8*cm)) - cell.append(Paragraph(poll.title, stylesheet['Ballot_title'])) - cell.append(Paragraph(_("Title")+": "+poll.application.title, stylesheet['Ballot_subtitle'])) - if poll.description: - cell.append(Paragraph(poll.description, stylesheet['Ballot_description'])) + cell.append(Paragraph(_("Application")+" #"+str(poll.application.number), stylesheet['Ballot_title'])) + cell.append(Paragraph(poll.application.title, stylesheet['Ballot_subtitle'])) + #if poll.description: + cell.append(Paragraph(str(poll.ballot)+". "+_("Vote"), stylesheet['Ballot_description'])) cell.append(Spacer(0,0.5*cm)) cell.append(Paragraph(circle+_("Yes"), stylesheet['Ballot_option'])) cell.append(Paragraph(circle+_("No"), stylesheet['Ballot_option'])) @@ -340,10 +340,10 @@ def print_application_poll(request, poll_id=None): doc.build(story) return response -def print_assignment_poll(request, poll_id=None, ballotnumber=1, posts=None): +def print_assignment_poll(request, poll_id=None): poll = Poll.objects.get(id=poll_id) response = HttpResponse(mimetype='application/pdf') - filename = u'filename=%s-%s-#%s.pdf;' % (_("Election"), poll.title.replace(' ','_'), ballotnumber) + filename = u'filename=%s-%s-#%s.pdf;' % (_("Election"), poll.assignment.name.replace(' ','_'), poll.ballot) response['Content-Disposition'] = filename.encode('utf-8') doc = SimpleDocTemplate(response, pagesize=A4, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0, showBoundary=False) story = [Spacer(0,0*cm)] @@ -351,18 +351,13 @@ def print_assignment_poll(request, poll_id=None, ballotnumber=1, posts=None): circle = " " cell = [] cell.append(Spacer(0,0.8*cm)) - cell.append(Paragraph(poll.title, stylesheet['Ballot_title'])) + cell.append(Paragraph(_("Election") + ": " + poll.assignment.name, stylesheet['Ballot_title'])) cell.append(Paragraph(poll.description, stylesheet['Ballot_subtitle'])) options = poll.get_options().order_by('user__user__first_name') - cell.append(Paragraph(ballotnumber+". "+_("ballot")+", "+str(len(options))+" "+ ungettext("candidate", "candidates", len(options))+", "+posts+" "+_("available posts"), stylesheet['Ballot_description'])) + cell.append(Paragraph(str(poll.ballot)+". "+_("ballot")+", "+str(len(options))+" "+ ungettext("candidate", "candidates", len(options))+", "+str(poll.assignment.posts)+" "+_("available posts"), stylesheet['Ballot_description'])) cell.append(Spacer(0,0.4*cm)) - if len(options) <= int(posts): - optiondecision = True - else: - optiondecision = False - - if optiondecision: + if poll.optiondecision: for option in options: o = str(option).rsplit("(",1) cell.append(Paragraph(o[0], stylesheet['Ballot_option_name']))