From d4d91c819409be605802128d82877fa50b06c268 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 15 Apr 2012 12:11:03 +0200 Subject: [PATCH] fixed printing applications --- openslides/application/models.py | 12 +++++++----- openslides/application/views.py | 11 +++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/openslides/application/models.py b/openslides/application/models.py index 26f2d436a..7d4719913 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -430,17 +430,20 @@ class Application(models.Model, SlideMixin): @property def results(self): + return self.get_poll_results() + + def get_poll_results(self): """ Return a list of voting results """ - # TODO: This will propably not work results = [] for poll in self.polls: for option in poll.get_options(): - #if poll.votesinvalid != None and poll.votescast != None: - results.append([option.yes, option.no, option.undesided, poll.votesinvalidf, poll.votescastf]) + if option.get_votes().exists(): + results.append((option.yes, option.no, option.contained, poll.print_votesinvalid(), poll.print_votescast())) return results + def slide(self): """ return the slide dict @@ -498,13 +501,12 @@ register_slidemodel(Application) class ApplicationOption(BaseOption): - def __getattr__(self, name): if name in ['yes', 'no', 'contained']: try: return self.get_votes().get(value=name) except Vote.DoesNotExist: - pass + return None raise AttributeError(name) diff --git a/openslides/application/views.py b/openslides/application/views.py index 4496fa8d9..b562550c4 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -509,7 +509,7 @@ def application_import(request): except ValueError: messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1)) continue - form = ApplicationForm({ 'title':title, 'text':text, 'reason':reason }) + form = ApplicationForm({'title': title, 'text': text, 'reason': reason}) if not form.is_valid(): messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1)) continue @@ -600,6 +600,7 @@ class ApplicationPDF(PDFView): application_id = self.kwargs['application_id'] except KeyError: application_id = None + if application_id is None: #print all applications title = config["application_pdf_title"] story.append(Paragraph(title, stylesheet['Heading1'])) @@ -679,15 +680,17 @@ class ApplicationPDF(PDFView): data.append([cell2a,cell2b]) data.append([cell3a,cell3b]) + poll_results = application.get_poll_results() + print poll_results # voting results - if len(application.results) > 0: + if poll_results: cell4a = [] cell4a.append(Paragraph("%s:" % _("Vote results"), stylesheet['Heading4'])) cell4b = [] ballotcounter = 0 - for result in application.results: + for result in poll_results: ballotcounter += 1 - if len(application.results) > 1: + if len(poll_results) > 1: cell4b.append(Paragraph("%s. %s" % (ballotcounter, _("Vote")), stylesheet['Bold'])) cell4b.append(Paragraph("%s: %s
%s: %s
%s: %s
%s: %s
%s: %s" % (_("Yes"), result[0], _("No"), result[1], _("Abstention"), result[2], _("Invalid"), result[3], _("Votes cast"), result[4]), stylesheet['Normal'])) cell4b.append(Spacer(0,0.2*cm))