Updated application PDF. Added vote results.

This commit is contained in:
Emanuel Schuetze 2011-09-06 22:22:29 +02:00
parent ecc728c8e9
commit bb38d8b85e
4 changed files with 119 additions and 30 deletions

View File

@ -17,6 +17,7 @@ from django.db.models import Max
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from openslides.participant.models import Profile
from openslides.system.api import config_get from openslides.system.api import config_get
@ -142,6 +143,18 @@ class Application(models.Model):
min_supporters = int(config_get('application_min_supporters')) min_supporters = int(config_get('application_min_supporters'))
return self.supporter.count() >= min_supporters return self.supporter.count() >= min_supporters
@property
def missing_supporters(self):
"""
Return number of missing supporters
"""
min_supporters = int(config_get('application_min_supporters'))
delta = min_supporters - self.supporter.count()
if delta > 0:
return delta
else:
return 0
def save(self, user=None, nonewversion=False): def save(self, user=None, nonewversion=False):
""" """
Save the Application, and create a new AVersion if necessary Save the Application, and create a new AVersion if necessary
@ -293,12 +306,15 @@ class Application(models.Model):
or (self.status == "per" \ or (self.status == "per" \
and user.has_perm("application.can_manage_application")): and user.has_perm("application.can_manage_application")):
actions.append("wit") actions.append("wit")
try:
# Check if the user can support and unspoort the application # Check if the user can support and unspoort the application
if self.status == "pub" \ if self.status == "pub" \
and user != self.submitter \ and user != self.submitter \
and user not in self.supporter.all(): and user not in self.supporter.all() \
and user.profile:
actions.append("support") actions.append("support")
except Profile.DoesNotExist:
pass
if self.status == "pub" and user in self.supporter.all(): if self.status == "pub" and user in self.supporter.all():
actions.append("unsupport") actions.append("unsupport")
@ -388,6 +404,18 @@ class Application(models.Model):
self.writelog(_("Poll created"), user) self.writelog(_("Poll created"), user)
return poll return poll
@property
def results(self):
"""
Return a list of voting results
"""
results = []
for poll in self.poll_set.all():
for option in poll.options:
if poll.votesinvalid != None and poll.votescast != None:
results.append([option.yes, option.no, option.undesided, poll.votesinvalid, poll.votescast])
return results
@models.permalink @models.permalink
def get_absolute_url(self, link='view'): def get_absolute_url(self, link='view'):
if link == 'view': if link == 'view':

View File

@ -60,8 +60,8 @@
<ul class="results"> <ul class="results">
{% for poll in polls %} {% for poll in polls %}
<li> <li>
{% if perms.application.can_manage_application %} {% if perms.application.can_manage_application and poll.has_vote %}
{% if poll.has_vote %}<a href="{% url application_poll_view poll.id %}">{% endif %} <a href="{% url application_poll_view poll.id %}">
{% endif %} {% endif %}
<b>{{ forloop.counter }}. {% trans "Vote" %}:</b> <b>{{ forloop.counter }}. {% trans "Vote" %}:</b>
{% if perms.application.can_manage_application %} {% if perms.application.can_manage_application %}

View File

@ -80,7 +80,8 @@ def view(request, application_id, newest=False):
'revisions': revisions, 'revisions': revisions,
'actions': actions, 'actions': actions,
'min_supporters': int(config_get('application_min_supporters')), 'min_supporters': int(config_get('application_min_supporters')),
'version': version 'version': version,
'results': application.results
} }

View File

@ -89,8 +89,13 @@ stylesheet.add(ParagraphStyle(name = 'Heading2',
stylesheet.add(ParagraphStyle(name = 'Heading3', stylesheet.add(ParagraphStyle(name = 'Heading3',
parent = stylesheet['Bold'], parent = stylesheet['Bold'],
fontSize = 12, fontSize = 12,
leading = 24), leading = 20),
alias = 'h3') alias = 'h3')
stylesheet.add(ParagraphStyle(name = 'Heading4',
parent = stylesheet['Bold'],
fontSize = 10,
leading = 20),
)
stylesheet.add(ParagraphStyle(name = 'Item', stylesheet.add(ParagraphStyle(name = 'Item',
parent = stylesheet['Normal'], parent = stylesheet['Normal'],
fontSize = 14, fontSize = 14,
@ -109,6 +114,11 @@ stylesheet.add(ParagraphStyle(name = 'Tablecell',
parent = stylesheet['Normal'], parent = stylesheet['Normal'],
fontSize = 9) fontSize = 9)
) )
stylesheet.add(ParagraphStyle(name = 'Signaturefield',
parent = stylesheet['Normal'],
spaceBefore = 15)
)
# Ballot stylesheets # Ballot stylesheets
stylesheet.add(ParagraphStyle(name = 'Ballot_title', stylesheet.add(ParagraphStyle(name = 'Ballot_title',
parent = stylesheet['Bold'], parent = stylesheet['Bold'],
@ -193,7 +203,7 @@ def firstPage(canvas, doc):
# footer (with page number) # footer (with page number)
canvas.setFont('Ubuntu',8) canvas.setFont('Ubuntu',8)
canvas.setFillGray(0.4) canvas.setFillGray(0.4)
canvas.drawString(10*cm, 1*cm, _("Page")+" 1") canvas.drawString(10*cm, 1*cm, _("Page")+" %s" % doc.page)
canvas.restoreState() canvas.restoreState()
@ -319,27 +329,78 @@ def print_passwords(request):
def get_application(application, story): def get_application(application, story):
# application number
if application.number is None: if application.number is None:
story.append(Paragraph(_("Application")+" #[-]", stylesheet['Heading1'])) story.append(Paragraph(_("Application No.")+" [-]", stylesheet['Heading1']))
else: else:
story.append(Paragraph(_("Application")+" #%s" % application.number, stylesheet['Heading1'])) story.append(Paragraph(_("Application Nr.")+" %s" % application.number, stylesheet['Heading1']))
story.append(Paragraph(application.title, stylesheet['Heading2'])) # title
story.append(Paragraph("%s" % application.text.replace('\r\n','<br/>'), stylesheet['Paragraph'])) story.append(Paragraph(_("Subject")+": "+application.title, stylesheet['Heading3']))
story.append(Paragraph(_("Reason")+":", stylesheet['Heading3']))
story.append(Paragraph("%s" % application.reason.replace('\r\n','<br/>'), stylesheet['Paragraph'])) # submitter
story.append(Paragraph(_("Submitter")+": %s" % unicode(application.submitter), stylesheet['Italic'])) cell1a = []
story.append(Paragraph(_("Created")+": %s" % application.time.strftime(_("%Y-%m-%d %H:%Mh")), stylesheet['Italic'])) cell1a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Submitter"), stylesheet['Heading4']))
supporters = "" cell1b = []
cell1b.append(Paragraph(unicode(application.submitter.profile), stylesheet['Normal']))
# supporters
cell2a = []
cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset id='counter'>" % _("Supporters"), stylesheet['Heading4']))
cell2b = []
for s in application.supporter.all(): for s in application.supporter.all():
supporters += "%s, " % unicode(s) cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(s.profile), stylesheet['Signaturefield']))
story.append(Paragraph(_("Supporter")+": %s" % supporters, stylesheet['Italic'])) for x in range(0,application.missing_supporters):
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield']))
cell2b.append(Spacer(0,0.2*cm))
# status
note = "" note = ""
for n in application.notes: for n in application.notes:
note += "%s " % unicode(n) note += "%s " % unicode(n)
cell3a = []
cell3a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Status"), stylesheet['Heading4']))
cell3b = []
if note != "": if note != "":
story.append(Paragraph(_("Status")+": %s | %s" % (application.get_status_display(), note), stylesheet['Italic'])) cell3b.append(Paragraph("%s | %s" % (application.get_status_display(), note), stylesheet['Normal']))
else: else:
story.append(Paragraph(_("Status")+": %s" % (application.get_status_display()), stylesheet['Italic'])) cell3b.append(Paragraph("%s" % application.get_status_display(), stylesheet['Normal']))
# voting results
cell4a = []
cell4a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Vote results"), stylesheet['Heading4']))
cell4b = []
ballotcounter = 0
for result in application.results:
ballotcounter += 1
if len(application.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))
# table
data = []
data.append([cell1a,cell1b])
data.append([cell2a,cell2b])
data.append([cell3a,cell3b])
data.append([cell4a,cell4b])
t=Table(data)
t._argW[0]=4.5*cm
t._argW[1]=11*cm
t.setStyle(TableStyle([ ('BOX', (0,0), (-1,-1), 1, colors.black),
('VALIGN', (0,0), (-1,-1), 'TOP'),
# ('SPAN',(-1,-1),(-2,-2)),
]))
story.append(t)
story.append(Spacer(0,1*cm))
# text
story.append(Paragraph("%s" % application.text.replace('\r\n','<br/>'), stylesheet['Paragraph']))
# reason
story.append(Paragraph(_("Reason")+":", stylesheet['Heading3']))
story.append(Paragraph("%s" % application.reason.replace('\r\n','<br/>'), stylesheet['Paragraph']))
return story return story
@ -350,10 +411,10 @@ def print_application(request, application_id=None):
response['Content-Disposition'] = filename.encode('utf-8') response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response) doc = SimpleDocTemplate(response)
doc.title = None doc.title = None
story = [Spacer(1,2*cm)] story = []
if application_id is None: #print all applications if application_id is None: #print all applications
doc.title = _("Applications") story.append(Paragraph(_("Applications"), stylesheet['Heading1']))
# List of applications # List of applications
for application in Application.objects.exclude(number=None).order_by('number'): for application in Application.objects.exclude(number=None).order_by('number'):
story.append(Paragraph(_("Application")+" #%s: %s" % (application.number, application.title), stylesheet['Heading3'])) story.append(Paragraph(_("Application")+" #%s: %s" % (application.number, application.title), stylesheet['Heading3']))
@ -361,14 +422,13 @@ def print_application(request, application_id=None):
for application in Application.objects.exclude(number=None).order_by('number'): for application in Application.objects.exclude(number=None).order_by('number'):
story.append(PageBreak()) story.append(PageBreak())
story = get_application(application, story) story = get_application(application, story)
else: # print selected application else: # print selected application
application = Application.objects.get(id=application_id) application = Application.objects.get(id=application_id)
filename = u'filename=%s%s.pdf;' % (_("Application"), str(application.number)) filename = u'filename=%s%s.pdf;' % (_("Application"), str(application.number))
response['Content-Disposition'] = filename.encode('utf-8') response['Content-Disposition'] = filename.encode('utf-8')
story = get_application(application, story) story = get_application(application, story)
doc.build(story, onFirstPage=firstPage, onLaterPages=laterPages) doc.build(story, onFirstPage=firstPage, onLaterPages=firstPage)
return response return response