fixed printing applications

This commit is contained in:
Oskar Hahn 2012-04-15 12:11:03 +02:00
parent f4ed79b68d
commit d4d91c8194
2 changed files with 14 additions and 9 deletions

View File

@ -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)

View File

@ -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("<font name='Ubuntu-Bold'>%s:</font>" % _("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 <br/> %s: %s <br/> %s: %s <br/> %s: %s <br/> %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))