From 6d3061f8af1c9f4fd35afb374f0bc3e24b7cd899 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 29 Jun 2012 00:19:06 +0200 Subject: [PATCH] cleaned poll pdf for assignment and application --- openslides/application/forms.py | 6 +-- openslides/application/models.py | 6 +-- openslides/application/views.py | 13 +++--- openslides/assignment/forms.py | 6 +-- openslides/assignment/models.py | 4 +- openslides/assignment/views.py | 72 ++++++++++++++------------------ 6 files changed, 50 insertions(+), 57 deletions(-) diff --git a/openslides/application/forms.py b/openslides/application/forms.py index a5a6a1ccd..aa10cf814 100644 --- a/openslides/application/forms.py +++ b/openslides/application/forms.py @@ -76,9 +76,9 @@ class ConfigForm(Form, CssClassMixin): required=False, label=_("Number of ballot papers (selection)"), choices=[ - ("1", _("Number of all delegates")), - ("2", _("Number of all participants")), - ("0", _("Use the following custum number")), + ("NUMBER_OF_DELEGATES", _("Number of all delegates")), + ("NUMBER_OF_ALL_PARTICIPANTS", _("Number of all participants")), + ("CUSTOM_NUMBER", _("Use the following custom number")), ] ) application_pdf_ballot_papers_number = IntegerField( diff --git a/openslides/application/models.py b/openslides/application/models.py index 3f483f063..e1f9c6768 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -574,9 +574,9 @@ from openslides.config.signals import default_config_value def default_config(sender, key, **kwargs): return { 'application_min_supporters': 0, - 'application_preamble': 'Die Versammlung möge beschließen,', - 'application_pdf_ballot_papers_selection': '1', - 'application_pdf_ballot_papers_number': '1', + 'application_preamble': _('The Assembly may decide,'), + 'application_pdf_ballot_papers_selection': 'CUSTOM_NUMBER', + 'application_pdf_ballot_papers_number': '8', 'application_pdf_title': _('Applications'), 'application_pdf_preamble': '', }.get(key) diff --git a/openslides/application/views.py b/openslides/application/views.py index 6df791c11..954140d8b 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -835,15 +835,16 @@ class ApplicationPollPDF(PDFView): # get ballot papers config values ballot_papers_selection = config["application_pdf_ballot_papers_selection"] ballot_papers_number = config["application_pdf_ballot_papers_number"] + # set number of ballot papers - if ballot_papers_selection == "1": + if ballot_papers_selection == "NUMBER_OF_DELEGATES": number = User.objects.filter(profile__type__iexact="delegate").count() - if ballot_papers_selection == "2": - number = int(User.objects.count() - 1) - if ballot_papers_selection == "0": + elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": + number = int(Profile.objects.count()) + else: # ballot_papers_selection == "CUSTOM_NUMBER" number = int(ballot_papers_number) - if number == 0: - number = 1 + number = max(1, number) + # print ballot papers if number > 0: for user in xrange(number/2): diff --git a/openslides/assignment/forms.py b/openslides/assignment/forms.py index 048790122..63768f0c2 100644 --- a/openslides/assignment/forms.py +++ b/openslides/assignment/forms.py @@ -43,9 +43,9 @@ class ConfigForm(Form, CssClassMixin): required=False, label=_("Number of ballot papers (selection)"), choices=( - ("1", _("Number of all delegates")), - ("2", _("Number of all participants")), - ("0", _("Use the following custum number")) + ("NUMBER_OF_DELEGATES", _("Number of all delegates")), + ("NUMBER_OF_ALL_PARTICIPANTS", _("Number of all participants")), + ("CUSTOM_NUMBER", _("Use the following custom number")) ) ) assignment_pdf_ballot_papers_number = forms.IntegerField( diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 2e71f99da..1dcbec92c 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -235,8 +235,8 @@ from openslides.config.signals import default_config_value def default_config(sender, key, **kwargs): return { 'assignment_publish_winner_results_only': False, - 'assignment_pdf_ballot_papers_selection': '1', - 'assignment_pdf_ballot_papers_number': '1', + 'assignment_pdf_ballot_papers_selection': 'CUSTOM_NUMBER', + 'assignment_pdf_ballot_papers_number': '8', 'assignment_pdf_title': _('Elections'), 'assignment_pdf_preamble': '', 'assignment_poll_vote_values': 'auto', diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 17ea40838..6f9b97b19 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -513,68 +513,60 @@ class AssignmentPollPDF(PDFView): data= [] # get ballot papers config values - number = 1 ballot_papers_selection = config["assignment_pdf_ballot_papers_selection"] ballot_papers_number = config["assignment_pdf_ballot_papers_number"] + + # set number of ballot papers + if ballot_papers_selection == "NUMBER_OF_DELEGATES": + number = User.objects.filter(profile__type__iexact="delegate").count() + elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": + number = int(Profile.objects.count()) + else: # ballot_papers_selection == "CUSTOM_NUMBER" + number = int(ballot_papers_number) + number = max(1, number) + # Choose kind of ballot paper if self.poll.yesnoabstain: for option in options: - o = str(option).split("(",1) - cell.append(Paragraph(o[0], stylesheet['Ballot_option_name'])) - if len(o) > 1: - cell.append(Paragraph("("+o[1], stylesheet['Ballot_option_group'])) + candidate = option.candidate + cell.append(Paragraph(candidate.user.get_full_name(), stylesheet['Ballot_option_name'])) + if candidate.group: + cell.append(Paragraph("(%s)" % candidate.group, stylesheet['Ballot_option_group'])) else: cell.append(Paragraph(" ", stylesheet['Ballot_option_group'])) cell.append(Paragraph(circle+_("Yes")+"      "+circle+_("No")+"      "+circle+_("Abstention"), stylesheet['Ballot_option_YNA'])) - # set number of ballot papers - if ballot_papers_selection == "1": - number = User.objects.filter(profile__type__iexact="delegate").count() - if ballot_papers_selection == "2": - number = int(User.objects.count() - 1) - if ballot_papers_selection == "0": - number = int(ballot_papers_number) # print ballot papers - for user in xrange(number/2): - data.append([cell,cell]) + for user in xrange(number / 2): + data.append([cell, cell]) rest = number % 2 if rest: - data.append([cell,'']) + data.append([cell, '']) if len(options) <= 2: - t=Table(data, 10.5*cm, 7.42*cm) + t = Table(data, 10.5*cm, 7.42*cm) elif len(options) <= 5: - t=Table(data, 10.5*cm, 14.84*cm) + t = Table(data, 10.5*cm, 14.84*cm) else: - t=Table(data, 10.5*cm, 29.7*cm) + t = Table(data, 10.5*cm, 29.7*cm) else: for option in options: - o = str(option).split("(",1) - cell.append(Paragraph(circle+o[0], stylesheet['Ballot_option_name'])) - if len(o) > 1: - cell.append(Paragraph("("+o[1], stylesheet['Ballot_option_group_right'])) + candidate = option.candidate + cell.append(Paragraph(circle + candidate.user.get_full_name(), stylesheet['Ballot_option_name'])) + if candidate.group: + cell.append(Paragraph("(%s)" % candidate.group, stylesheet['Ballot_option_group_right'])) else: cell.append(Paragraph(" ", stylesheet['Ballot_option_group_right'])) - # set number of ballot papers - if ballot_papers_selection == "1": - number = User.objects.filter(profile__type__iexact="delegate").count() - if ballot_papers_selection == "2": - number = int(User.objects.count() - 1) - if ballot_papers_selection == "0": - number = int(ballot_papers_number) - if number == 0: - number = 1 # print ballot papers - if number > 0: - for user in xrange(number/2): - data.append([cell,cell]) - rest = number % 2 - if rest: - data.append([cell,'']) + for user in xrange(number / 2): + data.append([cell, cell]) + rest = number % 2 + if rest: + data.append([cell, '']) if len(options) <= 4: - t=Table(data, 10.5*cm, 7.42*cm) + t = Table(data, 10.5*cm, 7.42*cm) elif len(options) <= 8: - t=Table(data, 10.5*cm, 14.84*cm) + t = Table(data, 10.5*cm, 14.84*cm) else: - t=Table(data, 10.5*cm, 29.7*cm) + t = Table(data, 10.5*cm, 29.7*cm) t.setStyle(TableStyle([ ('GRID', (0,0), (-1,-1), 0.25, colors.grey), ('VALIGN', (0,0), (-1,-1), 'TOP'),