Added assignment pdf.

This commit is contained in:
Emanuel Schuetze 2011-09-07 07:52:44 +02:00
parent d8a880105a
commit 5fd31f6ca6
5 changed files with 77 additions and 3 deletions

View File

@ -14,5 +14,6 @@
{% if perms.assignment.can_manage_assignment %} {% if perms.assignment.can_manage_assignment %}
<li class="{% active request '/assignment/new' %}"><a href="{% url assignment_new %}">{%trans "New election" %}</a></li> <li class="{% active request '/assignment/new' %}"><a href="{% url assignment_new %}">{%trans "New election" %}</a></li>
{% endif %} {% endif %}
<li><a href="{% url print_assignment %}"><img src="/static/images/icons/application-pdf.png"> {%trans 'Print all elections' %}</a></li>
</ul> </ul>
{% endblock %} {% endblock %}

View File

@ -6,8 +6,11 @@
<div class="box"> <div class="box">
<h4>{% trans "Status" %}:</h4> <h4>{% trans "Status" %}:</h4>
<h4 style="text-align: right;">
<a href="{% url print_assignment assignment.id %}"><img src="/static/images/icons/application-pdf.png" title="{% trans 'Print Election' %}"></a>
</h4>
<span clear="all"></span>
{% trans assignment.get_status_display %} {% trans assignment.get_status_display %}
<h4>{% trans "Number of available posts" %}:</h4> <h4>{% trans "Number of available posts" %}:</h4>
{{ assignment.posts }} {{ assignment.posts }}
</div> </div>

View File

@ -43,6 +43,12 @@ urlpatterns = patterns('assignment.views',
url(r'^assignment/poll/(?P<poll_id>\d+)/print$', 'print_assignment_poll', \ url(r'^assignment/poll/(?P<poll_id>\d+)/print$', 'print_assignment_poll', \
name='print_assignment_poll'), name='print_assignment_poll'),
url(r'^assignment/print$', 'print_assignment', \
name='print_assignment'),
url(r'^assignment/(?P<assignment_id>\d+)/print$', 'print_assignment', \
name='print_assignment'),
url(r'^assignment/(?P<assignment_id>\d+)/gen_poll$', 'gen_poll', \ url(r'^assignment/(?P<assignment_id>\d+)/gen_poll$', 'gen_poll', \
name='assignment_gen_poll'), name='assignment_gen_poll'),

View File

@ -21,7 +21,7 @@ from poll.forms import OptionResultForm, PollForm
from assignment.models import Assignment from assignment.models import Assignment
from assignment.forms import AssignmentForm, AssignmentRunForm from assignment.forms import AssignmentForm, AssignmentRunForm
from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request
from utils.pdf import print_assignment_poll from utils.pdf import print_assignment, print_assignment_poll
from participant.models import Profile from participant.models import Profile

View File

@ -33,8 +33,9 @@ from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont from reportlab.pdfbase.ttfonts import TTFont
from openslides.agenda.models import Item from openslides.agenda.models import Item
from openslides.application.models import Application
from openslides.agenda.api import children_list from openslides.agenda.api import children_list
from openslides.application.models import Application
from openslides.assignment.models import Assignment
from openslides.poll.models import Poll from openslides.poll.models import Poll
from openslides.participant.models import Profile from openslides.participant.models import Profile
from openslides.system.api import config_get from openslides.system.api import config_get
@ -420,6 +421,7 @@ def print_application(request, application_id=None):
if application_id is None: #print all applications if application_id is None: #print all applications
story.append(Paragraph(_("Applications"), stylesheet['Heading1'])) story.append(Paragraph(_("Applications"), stylesheet['Heading1']))
story.append(Spacer(0,0.75*cm))
# 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 No.")+" %s: %s" % (application.number, application.title), stylesheet['Heading3'])) story.append(Paragraph(_("Application No.")+" %s: %s" % (application.number, application.title), stylesheet['Heading3']))
@ -469,7 +471,69 @@ def print_application_poll(request, poll_id=None):
doc.build(story) doc.build(story)
return response return response
def get_assignment(assignment, story):
# title
story.append(Paragraph(_("Election")+": %s" % assignment.name, stylesheet['Heading1']))
story.append(Spacer(0,0.5*cm))
# posts
cell1a = []
cell1a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Number of available posts"), stylesheet['Bold']))
cell1b = []
cell1b.append(Paragraph(str(assignment.posts), stylesheet['Paragraph']))
# candidates
cell2a = []
cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset id='counter'>" % _("Candidates"), stylesheet['Heading4']))
cell2b = []
for c in assignment.candidates:
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(c), stylesheet['Signaturefield']))
if assignment.status == "sea":
for x in range(0,2*assignment.posts):
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield']))
cell2b.append(Spacer(0,0.2*cm))
# table
data = []
data.append([cell1a,cell1b])
data.append([cell2a,cell2b])
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'),
]))
story.append(t)
story.append(Spacer(0,1*cm))
# text
story.append(Paragraph("%s" % assignment.description.replace('\r\n','<br/>'), stylesheet['Paragraph']))
return story
@permission_required('application.can_see_application')
def print_assignment(request, assignment_id=None):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Elections")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
doc.title = None
story = []
if assignment_id is None: #print all applications
story.append(Paragraph(_("Elections"), stylesheet['Heading1']))
story.append(Spacer(0,0.75*cm))
# List of assignments
for assignment in Assignment.objects.order_by('name'):
story.append(Paragraph(assignment.name, stylesheet['Heading3']))
# Assignment details (each assignment on single page)
for assignment in Assignment.objects.order_by('name'):
story.append(PageBreak())
story = get_assignment(assignment, story)
else: # print selected assignment
assignment = Assignment.objects.get(id=assignment_id)
filename = u'filename=%s-%s.pdf;' % (_("Assignment"), assignment.name.replace(' ','_'))
response['Content-Disposition'] = filename.encode('utf-8')
story = get_assignment(assignment, story)
doc.build(story, onFirstPage=firstPage, onLaterPages=firstPage)
return response
@permission_required('application.can_manage_application') @permission_required('application.can_manage_application')
def print_assignment_poll(request, poll_id=None): def print_assignment_poll(request, poll_id=None):
poll = Poll.objects.get(id=poll_id) poll = Poll.objects.get(id=poll_id)