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 @property
def results(self): def results(self):
return self.get_poll_results()
def get_poll_results(self):
""" """
Return a list of voting results Return a list of voting results
""" """
# TODO: This will propably not work
results = [] results = []
for poll in self.polls: for poll in self.polls:
for option in poll.get_options(): for option in poll.get_options():
#if poll.votesinvalid != None and poll.votescast != None: if option.get_votes().exists():
results.append([option.yes, option.no, option.undesided, poll.votesinvalidf, poll.votescastf]) results.append((option.yes, option.no, option.contained, poll.print_votesinvalid(), poll.print_votescast()))
return results return results
def slide(self): def slide(self):
""" """
return the slide dict return the slide dict
@ -498,13 +501,12 @@ register_slidemodel(Application)
class ApplicationOption(BaseOption): class ApplicationOption(BaseOption):
def __getattr__(self, name): def __getattr__(self, name):
if name in ['yes', 'no', 'contained']: if name in ['yes', 'no', 'contained']:
try: try:
return self.get_votes().get(value=name) return self.get_votes().get(value=name)
except Vote.DoesNotExist: except Vote.DoesNotExist:
pass return None
raise AttributeError(name) raise AttributeError(name)

View File

@ -509,7 +509,7 @@ def application_import(request):
except ValueError: except ValueError:
messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1)) messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
continue continue
form = ApplicationForm({ 'title':title, 'text':text, 'reason':reason }) form = ApplicationForm({'title': title, 'text': text, 'reason': reason})
if not form.is_valid(): if not form.is_valid():
messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1)) messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
continue continue
@ -600,6 +600,7 @@ class ApplicationPDF(PDFView):
application_id = self.kwargs['application_id'] application_id = self.kwargs['application_id']
except KeyError: except KeyError:
application_id = None application_id = None
if application_id is None: #print all applications if application_id is None: #print all applications
title = config["application_pdf_title"] title = config["application_pdf_title"]
story.append(Paragraph(title, stylesheet['Heading1'])) story.append(Paragraph(title, stylesheet['Heading1']))
@ -679,15 +680,17 @@ class ApplicationPDF(PDFView):
data.append([cell2a,cell2b]) data.append([cell2a,cell2b])
data.append([cell3a,cell3b]) data.append([cell3a,cell3b])
poll_results = application.get_poll_results()
print poll_results
# voting results # voting results
if len(application.results) > 0: if poll_results:
cell4a = [] cell4a = []
cell4a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Vote results"), stylesheet['Heading4'])) cell4a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Vote results"), stylesheet['Heading4']))
cell4b = [] cell4b = []
ballotcounter = 0 ballotcounter = 0
for result in application.results: for result in poll_results:
ballotcounter += 1 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" % (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(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)) cell4b.append(Spacer(0,0.2*cm))