Automated merge with ssh://openslides.org/openslides

This commit is contained in:
Emanuel Schuetze 2012-04-13 23:52:48 +02:00
commit 3817a03aa8
8 changed files with 478 additions and 308 deletions

View File

@ -13,7 +13,7 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from agenda.views import Overview, View, SetActive, SetClosed, ItemUpdate, ItemCreate, ItemDelete, ItemPDF from agenda.views import Overview, View, SetActive, SetClosed, ItemUpdate, ItemCreate, ItemDelete, ItemPDF
urlpatterns = patterns('agenda.views', urlpatterns = patterns('',
url(r'^$', url(r'^$',
Overview.as_view(), Overview.as_view(),
name='item_overview', name='item_overview',

View File

@ -13,84 +13,127 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from application.views import ViewPoll, ActivatePoll from application.views import ViewPoll, ActivatePoll, ApplicationPDF, ApplicationPollPDF
urlpatterns = patterns('application.views', urlpatterns = patterns('application.views',
url(r'^application/$', 'overview', \ url(r'^$',
name='application_overview'), 'overview',
name='application_overview',
),
url(r'^application/(?P<application_id>\d+)/$', 'view', \ url(r'^(?P<application_id>\d+)/$',
name='application_view'), 'view',
name='application_view',
),
url(r'^application/(?P<application_id>\d+)/newest/$', 'view', {'newest': True}, \ url(r'^(?P<application_id>\d+)/newest/$',
name='application_view_newest'), 'view',
{'newest': True},
name='application_view_newest',
),
url(r'^application/new/$', 'edit', \ url(r'^new/$',
name='application_new'), 'edit',
name='application_new',
),
url(r'^application/import/$', 'application_import', \ url(r'^import/$',
name='application_import'), 'application_import',
name='application_import',
),
url(r'^application/(?P<application_id>\d+)/edit/$', 'edit', \ url(r'^(?P<application_id>\d+)/edit/$',
name='application_edit'), 'edit',
name='application_edit',
),
url(r'^application/(?P<application_id>\d+)/del/$', 'delete', \ url(r'^(?P<application_id>\d+)/del/$',
name='application_delete'), 'delete',
name='application_delete',
),
url(r'^application/(?P<application_id>\d+)/setnumber/$', 'set_number', \ url(r'^(?P<application_id>\d+)/setnumber/$',
name='application_set_number'), 'set_number',
name='application_set_number',
),
url(r'^application/(?P<application_id>\d+)/setstatus/' \ url(r'^(?P<application_id>\d+)/setstatus/' '(?P<status>[a-z]{3})/$',
'(?P<status>[a-z]{3})/$', 'set_status', \ 'set_status',
name='application_set_status'), name='application_set_status',
),
url(r'^application/(?P<application_id>\d+)/permit/$', 'permit', \ url(r'^(?P<application_id>\d+)/permit/$',
name='application_permit'), 'permit',
name='application_permit',
),
url(r'^application/version/(?P<aversion_id>\d+)/permit/$', 'permit_version', \ url(r'^version/(?P<aversion_id>\d+)/permit/$',
name='application_version_permit'), 'permit_version',
name='application_version_permit',
),
url(r'^application/version/(?P<aversion_id>\d+)/reject/$', 'reject_version', \ url(r'^version/(?P<aversion_id>\d+)/reject/$',
name='application_version_reject'), 'reject_version',
name='application_version_reject',
),
url(r'^application/(?P<application_id>\d+)/notpermit/$', 'notpermit', \ url(r'^(?P<application_id>\d+)/notpermit/$',
name='application_notpermit'), 'notpermit',
name='application_notpermit',
),
url(r'^application/(?P<application_id>\d+)/reset/$', 'reset', \ url(r'^(?P<application_id>\d+)/reset/$',
name='application_reset'), 'reset',
name='application_reset',
),
url(r'^application/(?P<application_id>\d+)/support/$', 'support', \ url(r'^(?P<application_id>\d+)/support/$',
name='application_support'), 'support',
name='application_support',
),
url(r'^application/(?P<application_id>\d+)/unsupport/$', 'unsupport', \ url(r'^(?P<application_id>\d+)/unsupport/$',
name='application_unsupport'), 'unsupport',
name='application_unsupport',
),
url(r'^application/(?P<application_id>\d+)/set_active/$', 'set_active', url(r'^(?P<application_id>\d+)/set_active/$',
name='application_activate_item'), 'set_active',
name='application_activate_item',
),
url(r'^application/(?P<application_id>\d+)/gen_poll/$', 'gen_poll', \ url(r'^(?P<application_id>\d+)/gen_poll/$',
name='application_gen_poll'), 'gen_poll',
name='application_gen_poll',
),
url(r'^application/print/$', 'print_application', \ url(r'^print/$',
name='print_applications'), ApplicationPDF.as_view(),
name='print_applications',
),
url(r'^application/(?P<application_id>\d+)/print/$', 'print_application', \ url(r'^(?P<application_id>\d+)/print/$',
name='print_application'), ApplicationPDF.as_view(),
name='print_application',
),
url(r'^application/poll/(?P<poll_id>\d+)/print/$', 'print_application_poll', \ url(r'^poll/(?P<poll_id>\d+)/print/$',
name='print_application_poll'), ApplicationPollPDF.as_view(),
name='print_application_poll',
),
url(r'^application/poll/(?P<poll_id>\d+)/$', url(r'^poll/(?P<poll_id>\d+)/$',
ViewPoll.as_view(), ViewPoll.as_view(),
name='application_poll_view', name='application_poll_view',
), ),
url(r'^application/poll/(?P<poll_id>\d+)/activate/$', url(r'^poll/(?P<poll_id>\d+)/activate/$',
ActivatePoll.as_view(), ActivatePoll.as_view(),
name='application_poll_activate', name='application_poll_activate',
), ),
url(r'^application/poll/(?P<poll_id>\d+)/del/$', 'delete_poll', \ url(r'^poll/(?P<poll_id>\d+)/del/$',
name='application_poll_delete'), 'delete_poll',
name='application_poll_delete',
),
) )

View File

@ -13,6 +13,7 @@ from __future__ import with_statement
import csv import csv
import utils.csv_ext import utils.csv_ext
import os
from django.shortcuts import redirect from django.shortcuts import redirect
from django.contrib import messages from django.contrib import messages
@ -24,7 +25,14 @@ from django.utils.translation import ungettext
from django.db import transaction from django.db import transaction
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle
from system import config from system import config
from settings import SITE_ROOT
from utils.pdf import stylesheet
from utils.views import PDFView
from agenda.models import Item from agenda.models import Item
@ -45,8 +53,6 @@ from utils.utils import template, permission_required, \
from utils.views import FormView from utils.views import FormView
from utils.template import Tab from utils.template import Tab
from utils.pdf import print_application, print_application_poll
from participant.api import gen_username, gen_password from participant.api import gen_username, gen_password
@permission_required('application.can_see_application') @permission_required('application.can_see_application')
@ -479,7 +485,7 @@ def reject_version(request, aversion_id):
return redirect(reverse('application_view', args=[application.id])) return redirect(reverse('application_view', args=[application.id]))
@permission_required('application.can_manage_applications') @permission_required('application.can_manage_application')
@template('application/import.html') @template('application/import.html')
def application_import(request): def application_import(request):
try: try:
@ -598,6 +604,177 @@ def application_import(request):
} }
class ApplicationPDF(PDFView):
permission_required = 'application.can_manage_application'
filename = u'filename=%s.pdf;' % _("Applications")
top_space = 0
def append_to_pdf(self, story):
try:
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']))
preamble = config["application_pdf_preamble"]
if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm))
# List of applications
for application in Application.objects.order_by('number'):
if application.number:
story.append(Paragraph(_("Application No.")+" %s: %s" % (application.number, application.title), stylesheet['Heading3']))
else:
story.append(Paragraph(_("Application No.")+"&nbsp;&nbsp;&nbsp;: %s" % (application.title), stylesheet['Heading3']))
# Applications details (each application on single page)
for application in Application.objects.order_by('number'):
story.append(PageBreak())
story = self.get_application(application, story)
else: # print selected application
application = Application.objects.get(id=application_id)
if application.number:
number = application.number
else:
number = ""
filename = u'filename=%s%s.pdf;' % (_("Application"), str(number))
story = self.get_application(application, story)
def get_application(self, application, story):
# application number
if application.number:
story.append(Paragraph(_("Application No.")+" %s" % application.number, stylesheet['Heading1']))
else:
story.append(Paragraph(_("Application No."), stylesheet['Heading1']))
# submitter
cell1a = []
cell1a.append(Spacer(0,0.2*cm))
cell1a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Submitter"), stylesheet['Heading4']))
cell1b = []
cell1b.append(Spacer(0,0.2*cm))
if application.status == "pub":
cell1b.append(Paragraph("__________________________________________",stylesheet['Signaturefield']))
cell1b.append(Spacer(0,0.1*cm))
cell1b.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+unicode(application.submitter.profile), stylesheet['Small']))
cell1b.append(Spacer(0,0.2*cm))
else:
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():
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(s.profile), stylesheet['Signaturefield']))
if application.status == "pub":
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 = ""
for n in application.notes:
note += "%s " % unicode(n)
cell3a = []
cell3a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Status"), stylesheet['Heading4']))
cell3b = []
if note != "":
if application.status == "pub":
cell3b.append(Paragraph(note, stylesheet['Normal']))
else:
cell3b.append(Paragraph("%s | %s" % (application.get_status_display(), note), stylesheet['Normal']))
else:
cell3b.append(Paragraph("%s" % application.get_status_display(), stylesheet['Normal']))
# table
data = []
data.append([cell1a,cell1b])
data.append([cell2a,cell2b])
data.append([cell3a,cell3b])
# voting results
if len(application.results) > 0:
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))
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'),
]))
story.append(t)
story.append(Spacer(0,1*cm))
# title
story.append(Paragraph(application.title, stylesheet['Heading3']))
# 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
class ApplicationPollPDF(PDFView):
permission_required = 'application.can_manage_application'
top_space = 0
def get(self, request, *args, **kwargs):
self.poll = ApplicationPoll.objects.get(id=self.kwargs['poll_id'])
return super(ApplicationPollPDF, self).get(request, *args, **kwargs)
def get_filename(self):
filename = u'filename=%s%s_%s.pdf;' % (_("Application"), str(self.poll.application.number), _("Poll"))
return filename
def append_to_pdf(self, story):
imgpath = os.path.join(SITE_ROOT, 'static/images/circle.png')
circle = "<img src='%s' width='15' height='15'/>&nbsp;&nbsp;" % imgpath
cell = []
cell.append(Spacer(0,0.8*cm))
cell.append(Paragraph(_("Application No.")+" "+str(self.poll.application.number), stylesheet['Ballot_title']))
cell.append(Paragraph(self.poll.application.title, stylesheet['Ballot_subtitle']))
#cell.append(Paragraph(str(self.poll.ballot)+". "+_("Vote"), stylesheet['Ballot_description']))
cell.append(Spacer(0,0.5*cm))
cell.append(Paragraph(circle+_("Yes"), stylesheet['Ballot_option']))
cell.append(Paragraph(circle+_("No"), stylesheet['Ballot_option']))
cell.append(Paragraph(circle+_("Abstention"), stylesheet['Ballot_option']))
data= []
number = 1
# get ballot papers config values
ballot_papers_selection = config["application_pdf_ballot_papers_selection"]
ballot_papers_number = config["application_pdf_ballot_papers_number"]
# set number of ballot papers
if ballot_papers_selection == "1":
number = User.objects.filter(profile__type__iexact="delegate").count()
if ballot_papers_selection == "2":
number = int(User.objects.count() - 1)
if ballot_papers_selection == "0":
number = int(ballot_papers_number)
# print ballot papers
for user in xrange(number/2):
data.append([cell,cell])
rest = number % 2
if rest:
data.append([cell,''])
t=Table(data, 10.5*cm, 7.42*cm)
t.setStyle(TableStyle([ ('GRID', (0,0), (-1,-1), 0.25, colors.grey),
('VALIGN', (0,0), (-1,-1), 'TOP'),
]))
story.append(t)
class Config(FormView): class Config(FormView):
permission_required = 'system.can_manage_system' permission_required = 'system.can_manage_system'
form_class = ConfigForm form_class = ConfigForm

View File

@ -15,65 +15,106 @@ from django.conf.urls.defaults import *
from assignment.views import ViewPoll #, ActivatePoll from assignment.views import ViewPoll #, ActivatePoll
urlpatterns = patterns('assignment.views', urlpatterns = patterns('assignment.views',
url(r'^assignment/$', 'get_overview', \ url(r'^$',
name='assignment_overview'), 'get_overview',
name='assignment_overview',
url(r'^assignment/(?P<assignment_id>\d+)$', 'view', \
name='assignment_view'),
url(r'^assignment/new$', 'edit', \
name='assignment_new'),
url(r'^assignment/(?P<assignment_id>\d+)/edit$', 'edit', \
name='assignment_edit'),
url(r'^assignment/(?P<assignment_id>\d+)/del$', 'delete', \
name='assignment_delete'),
url(r'^assignment/(?P<assignment_id>\d+)/setstatus/(?P<status>[a-z]{3})$', 'set_status', \
name='assignment_set_status'),
url(r'^assignment/(?P<assignment_id>\d+)/run$', 'run', \
name='assignment_run'),
url(r'^assignment/(?P<assignment_id>\d+)/delrun$', 'delrun', \
name='assignment_delrun'),
url(r'^assignment/(?P<assignment_id>\d+)/delother/(?P<profile_id>\d+)$', 'delother', \
name='assignment_delother'),
url(r'^assignment/(?P<assignment_id>\d+)/set_active/$', 'set_active',
name='assignment_activate_item'),
url(r'^assignment/poll/(?P<poll_id>\d+)/print$', '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', \
name='assignment_gen_poll'),
url(r'^assignment/poll/(?P<poll_id>\d+)$',
ViewPoll.as_view(),
name='assignment_poll_view'
), ),
url(r'^assignment/poll/(?P<poll_id>\d+)/del$', 'delete_poll', \ url(r'^(?P<assignment_id>\d+)$',
name='assignment_poll_delete'), 'view',
name='assignment_view'),
url(r'^assignment/poll/(?P<poll_id>\d+)/pub/$', 'set_published', {'published': True}, url(r'^new$',
name='assignment_poll_publish'), 'edit',
name='assignment_new',
),
url(r'^assignment/poll/(?P<poll_id>\d+)/notpub/$', 'set_published', {'published': False}, url(r'^(?P<assignment_id>\d+)/edit$',
name='assignment_poll_notpublish'), 'edit',
name='assignment_edit',
),
url(r'^assignment/(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$', 'set_elected', {'elected': True}, \ url(r'^(?P<assignment_id>\d+)/del$',
name='assignment_user_elected'), 'delete',
name='assignment_delete',
),
url(r'^assignment/(?P<assignment_id>\d+)/notelected/(?P<profile_id>\d+)$', 'set_elected', {'elected': False}, \ url(r'^(?P<assignment_id>\d+)/setstatus/(?P<status>[a-z]{3})$',
name='assignment_user_not_elected'), 'set_status',
name='assignment_set_status',
),
url(r'^(?P<assignment_id>\d+)/run$',
'run',
name='assignment_run',
),
url(r'^(?P<assignment_id>\d+)/delrun$',
'delrun',
name='assignment_delrun',
),
url(r'^(?P<assignment_id>\d+)/delother/(?P<profile_id>\d+)$',
'delother',
name='assignment_delother',
),
url(r'^(?P<assignment_id>\d+)/set_active/$',
'set_active',
name='assignment_activate_item',
),
url(r'^poll/(?P<poll_id>\d+)/print$',
'print_assignment_poll',
name='print_assignment_poll',
),
url(r'^print$',
'print_assignment',
name='print_assignment',
),
url(r'^(?P<assignment_id>\d+)/print$',
'print_assignment',
name='print_assignment',
),
url(r'^(?P<assignment_id>\d+)/gen_poll$',
'gen_poll',
name='assignment_gen_poll',
),
url(r'^poll/(?P<poll_id>\d+)$',
ViewPoll.as_view(),
name='assignment_poll_view',
),
url(r'^poll/(?P<poll_id>\d+)/del$',
'delete_poll',
name='assignment_poll_delete',
),
url(r'^poll/(?P<poll_id>\d+)/pub/$',
'set_published',
{'published': True},
name='assignment_poll_publish',
),
url(r'^poll/(?P<poll_id>\d+)/notpub/$',
'set_published',
{'published': False},
name='assignment_poll_notpublish',
),
url(r'^(?P<assignment_id>\d+)/elected/(?P<profile_id>\d+)$',
'set_elected',
{'elected': True},
name='assignment_user_elected',
),
url(r'^(?P<assignment_id>\d+)/notelected/(?P<profile_id>\d+)$',
'set_elected',
{'elected': False},
name='assignment_user_not_elected',
),
) )

View File

@ -14,35 +14,103 @@ from django.conf.urls.defaults import *
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
urlpatterns = patterns('participant.views', urlpatterns = patterns('participant.views',
url(r'^participant/$', 'get_overview', name='user_overview'), url(r'^$',
url(r'^participant/new$', 'edit', name='user_new'), 'get_overview',
url(r'^participant/(?P<user_id>\d+)/edit$', 'edit', name='user_edit'), name='user_overview',
url(r'^participant/print$', 'print_userlist', name='user_print'), ),
url(r'^participant/(?P<user_id>\d+)/del$', 'user_delete', name='user_delete'),
url(r'^participant/(?P<user_id>\d+)/active/$', 'user_set_active', {'active': True}, name='user_active'),
url(r'^participant/(?P<user_id>\d+)/inactive/$', 'user_set_active', {'active': False}, name='user_inactive'),
url(r'^participant/(?P<user_id>\d+)/superuser/$', 'user_set_superuser', {'superuser': True}, name='user_superuser'),
url(r'^participant/(?P<user_id>\d+)/normaluser/$', 'user_set_superuser', {'superuser': False}, name='user_normaluser'),
url(r'^participant/import$', 'user_import', name='user_import'), url(r'^new$',
url(r'^participant/group/$', 'get_group_overview', name='user_group_overview'), 'edit',
url(r'^participant/group/new$', 'group_edit', name='user_group_new'), name='user_new',
url(r'^participant/group/(?P<group_id>\d+)/edit$', 'group_edit', name='user_group_edit'), ),
url(r'^participant/group/(?P<group_id>\d+)/del$', 'group_delete', name='user_group_delete'),
url(r'^user/settings$', 'user_settings', name='user_settings'), url(r'^(?P<user_id>\d+)/edit$',
url(r'^participant/resetpassword/(?P<user_id>\d+)$', 'reset_password', name='user_reset_password'), 'edit',
url(r'^participant/passwords/print$', 'print_passwords', name='print_passwords'), name='user_edit',
),
url(r'^print$',
'print_userlist',
name='user_print',
),
url(r'^(?P<user_id>\d+)/del$',
'user_delete',
name='user_delete',
),
url(r'^(?P<user_id>\d+)/active/$',
'user_set_active',
{'active': True},
name='user_active',
),
url(r'^(?P<user_id>\d+)/inactive/$',
'user_set_active',
{'active': False},
name='user_inactive',
),
url(r'^(?P<user_id>\d+)/superuser/$',
'user_set_superuser',
{'superuser': True},
name='user_superuser',
),
url(r'^(?P<user_id>\d+)/normaluser/$',
'user_set_superuser',
{'superuser': False},
name='user_normaluser',
),
url(r'^import$',
'user_import',
name='user_import',
),
url(r'^group/$',
'get_group_overview',
name='user_group_overview',
),
url(r'^group/new$',
'group_edit',
name='user_group_new',
),
url(r'^group/(?P<group_id>\d+)/edit$',
'group_edit',
name='user_group_edit',
),
url(r'^group/(?P<group_id>\d+)/del$',
'group_delete',
name='user_group_delete',
),
url(r'^user/settings$',
'user_settings',
name='user_settings',
),
url(r'^resetpassword/(?P<user_id>\d+)$',
'reset_password',
name='user_reset_password',
),
url(r'^passwords/print$',
'print_passwords',
name='print_passwords',
),
) )
urlpatterns += patterns('django.contrib.auth.views', urlpatterns += patterns('django.contrib.auth.views',
url( url(r'^login/$',
r'^login/$',
'login', 'login',
{'template_name': 'participant/login.html'}, {'template_name': 'participant/login.html'},
name='user_login', name='user_login',
), ),
url( url(r'^logout/$',
r'^logout/$',
'logout_then_login', 'logout_then_login',
name='user_logout', name='user_logout',
) )

View File

@ -26,9 +26,9 @@ urlpatterns = patterns('',
)), )),
(r'^agenda/', include('agenda.urls')), (r'^agenda/', include('agenda.urls')),
(r'', include('application.urls')), (r'^application/', include('application.urls')),
(r'', include('participant.urls')), (r'^assignment/', include('assignment.urls')),
(r'', include('assignment.urls')), (r'^participant/', include('participant.urls')),
(r'config/', include('system.urls')), (r'config/', include('system.urls')),
(r'projector/', include('projector.urls')), (r'projector/', include('projector.urls')),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}),

View File

@ -35,7 +35,6 @@ 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.application.models import Application
from openslides.assignment.models import Assignment from openslides.assignment.models import Assignment
#from openslides.poll.models import Poll, Option
from openslides.participant.models import Profile from openslides.participant.models import Profile
from system import config from system import config
from openslides.settings import SITE_ROOT from openslides.settings import SITE_ROOT
@ -297,180 +296,6 @@ def print_passwords(request):
return response return response
def get_application(application, story):
# application number
if application.number:
story.append(Paragraph(_("Application No.")+" %s" % application.number, stylesheet['Heading1']))
else:
story.append(Paragraph(_("Application No."), stylesheet['Heading1']))
# submitter
cell1a = []
cell1a.append(Spacer(0,0.2*cm))
cell1a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Submitter"), stylesheet['Heading4']))
cell1b = []
cell1b.append(Spacer(0,0.2*cm))
if application.status == "pub":
cell1b.append(Paragraph("__________________________________________",stylesheet['Signaturefield']))
cell1b.append(Spacer(0,0.1*cm))
cell1b.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+unicode(application.submitter.profile), stylesheet['Small']))
cell1b.append(Spacer(0,0.2*cm))
else:
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():
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(s.profile), stylesheet['Signaturefield']))
if application.status == "pub":
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 = ""
for n in application.notes:
note += "%s " % unicode(n)
cell3a = []
cell3a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font>" % _("Status"), stylesheet['Heading4']))
cell3b = []
if note != "":
if application.status == "pub":
cell3b.append(Paragraph(note, stylesheet['Normal']))
else:
cell3b.append(Paragraph("%s | %s" % (application.get_status_display(), note), stylesheet['Normal']))
else:
cell3b.append(Paragraph("%s" % application.get_status_display(), stylesheet['Normal']))
# table
data = []
data.append([cell1a,cell1b])
data.append([cell2a,cell2b])
data.append([cell3a,cell3b])
# voting results
if len(application.results) > 0:
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))
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'),
]))
story.append(t)
story.append(Spacer(0,1*cm))
# title
story.append(Paragraph(application.title, stylesheet['Heading3']))
# 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
@permission_required('application.can_see_application')
def print_application(request, application_id=None):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("Applications")
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response)
doc.title = None
story = []
if application_id is None: #print all applications
title = config["application_pdf_title"]
story.append(Paragraph(title, stylesheet['Heading1']))
preamble = config["application_pdf_preamble"]
if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm))
# List of applications
for application in Application.objects.order_by('number'):
if application.number:
story.append(Paragraph(_("Application No.")+" %s: %s" % (application.number, application.title), stylesheet['Heading3']))
else:
story.append(Paragraph(_("Application No.")+"&nbsp;&nbsp;&nbsp;: %s" % (application.title), stylesheet['Heading3']))
# Applications details (each application on single page)
for application in Application.objects.order_by('number'):
story.append(PageBreak())
story = get_application(application, story)
else: # print selected application
application = Application.objects.get(id=application_id)
if application.number:
number = application.number
else:
number = ""
filename = u'filename=%s%s.pdf;' % (_("Application"), str(number))
response['Content-Disposition'] = filename.encode('utf-8')
story = get_application(application, story)
doc.build(story, onFirstPage=firstPage, onLaterPages=firstPage)
return response
@permission_required('application.can_manage_application')
def print_application_poll(request, poll_id=None):
poll = Poll.objects.get(id=poll_id)
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s%s_%s.pdf;' % (_("Application"), str(poll.application.number), _("Poll"))
response['Content-Disposition'] = filename.encode('utf-8')
doc = SimpleDocTemplate(response, pagesize=A4, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0, showBoundary=False)
story = [Spacer(0,0*cm)]
imgpath = os.path.join(SITE_ROOT, 'static/images/circle.png')
circle = "<img src='%s' width='15' height='15'/>&nbsp;&nbsp;" % imgpath
cell = []
cell.append(Spacer(0,0.8*cm))
cell.append(Paragraph(_("Application No.")+" "+str(poll.application.number), stylesheet['Ballot_title']))
cell.append(Paragraph(poll.application.title, stylesheet['Ballot_subtitle']))
cell.append(Paragraph(str(poll.ballot)+". "+_("Vote"), stylesheet['Ballot_description']))
cell.append(Spacer(0,0.5*cm))
cell.append(Paragraph(circle+_("Yes"), stylesheet['Ballot_option']))
cell.append(Paragraph(circle+_("No"), stylesheet['Ballot_option']))
cell.append(Paragraph(circle+_("Abstention"), stylesheet['Ballot_option']))
data= []
number = 1
# get ballot papers config values
ballot_papers_selection = config["application_pdf_ballot_papers_selection"]
ballot_papers_number = config["application_pdf_ballot_papers_number"]
# set number of ballot papers
if ballot_papers_selection == "1":
number = User.objects.filter(profile__type__iexact="delegate").count()
if ballot_papers_selection == "2":
number = int(User.objects.count() - 1)
if ballot_papers_selection == "0":
number = int(ballot_papers_number)
# print ballot papers
for user in xrange(number/2):
data.append([cell,cell])
rest = number % 2
if rest:
data.append([cell,''])
t=Table(data, 10.5*cm, 7.42*cm)
t.setStyle(TableStyle([ ('GRID', (0,0), (-1,-1), 0.25, colors.grey),
('VALIGN', (0,0), (-1,-1), 'TOP'),
]))
story.append(t)
doc.build(story)
return response
def get_assignment_votes(assignment): def get_assignment_votes(assignment):
votes = [] votes = []
for candidate in assignment.candidates: for candidate in assignment.candidates:

View File

@ -1,3 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.utils.views
~~~~~~~~~~~~~~~~~~~~~~
Views for utils.
:copyright: 2011 by the OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
try: try:
import json import json
except ImportError: except ImportError:
@ -192,6 +204,10 @@ class DeleteView(RedirectView, SingleObjectMixin):
class PDFView(PermissionMixin, View): class PDFView(PermissionMixin, View):
filename = 'No_Name' filename = 'No_Name'
top_space = 3
def get_top_space(self):
return self.top_space
def render_to_response(self, filename): def render_to_response(self, filename):
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
@ -200,7 +216,7 @@ class PDFView(PermissionMixin, View):
buffer = StringIO() buffer = StringIO()
pdf_document = SimpleDocTemplate(buffer) pdf_document = SimpleDocTemplate(buffer)
story = [Spacer(1,3*cm)] story = [Spacer(1, self.get_top_space()*cm)]
self.append_to_pdf(story) self.append_to_pdf(story)