Print password pdf with url and welcometext.

This commit is contained in:
Emanuel Schuetze 2011-09-04 00:54:45 +02:00
parent ceb9a3b4c3
commit a05b576f9e
8 changed files with 58 additions and 8 deletions

View File

@ -15,6 +15,7 @@
<li><a href="{% url user_print %}"><img src="/static/images/icons/application-pdf.png"> {%trans 'Print participant list' %}</a></li>
<li><a href="{% url user_import %}"> {%trans 'Import' %}</a></li>
<li><a href="{% url user_gen_passwords %}">{% trans 'Generate first passwords' %}</a></li>
<li><a href="{% url print_passwords %}"><img src="/static/images/icons/application-pdf.png">{% trans 'Print password list' %}</a></li>
{% endif %}
</ul>
{% endblock %}

View File

@ -29,6 +29,7 @@ urlpatterns = patterns('participant.views',
url(r'^user/settings$', 'user_settings', name='user_settings'),
url(r'^participant/genpasswords$', 'gen_passwords', name='user_gen_passwords'),
url(r'^participant/resetpassword/(?P<user_id>\d+)$', 'reset_password', name='user_reset_passwords'),
url(r'^participant/passwords/print$', 'print_passwords', name='print_passwords'),
)
urlpatterns += patterns('django.contrib.auth.views',

View File

@ -25,7 +25,7 @@ from participant.models import Profile, set_first_user_passwords
from participant.api import gen_username
from participant.forms import UserForm, UsernameForm, ProfileForm, UsersettingsForm, UserImportForm, GroupForm, AdminPasswordChangeForm
from utils.utils import template, permission_required, gen_confirm_form
from utils.pdf import print_userlist
from utils.pdf import print_userlist, print_passwords
from django.db.models import Avg, Max, Min, Count

View File

@ -10,7 +10,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
from django.forms import Form, CharField, TextInput, BooleanField, IntegerField
from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, Textarea
from django.utils.translation import ugettext as _
from system.api import config_get
@ -18,8 +18,11 @@ class SystemConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
user_registration = BooleanField(label=_("User registration"), required=False)
#user_registration = BooleanField(label=_("User registration"), required=False)
system_url = CharField(widget=TextInput(), required=False, label=_("System URL"))
system_welcometext = CharField(widget=Textarea(), required=False, label=_("Welcome text (for password PDF)"))
class EventConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
@ -36,4 +39,6 @@ class ApplicationConfigForm(Form):
application_min_supporters = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Number of (minimum) required supporters for a application"),initial=4, min_value=0, max_value=8)
application_preamble = CharField(widget=TextInput(), required=False, label=_("Application preamble"))

View File

@ -17,7 +17,7 @@ DEFAULT_DATA = {
'event_description': 'Presentation and voting system',
'application_min_supporters': 4,
'application_preamble': 'Die Versammlung möge beschließen,',
'user_registration': True,
'sysem_url': 'http://openslides:8000',
}
class Config(models.Model):

View File

@ -7,6 +7,6 @@
<h4 class="sectiontitle">{%trans "Configuration" %}</h4>
<ul>
<li class="{% if request.path == url_config_general %}selected{% endif %}"><a href="{% url config_general %}">{%trans "General" %}</a></li>
{# <li class="{% if request.path == url_config_system %}selected{% endif %}"><a href="{% url config_system %}">{%trans "System" %}</a></li> #}
<li class="{% if request.path == url_config_system %}selected{% endif %}"><a href="{% url config_system %}">{%trans "System" %}</a></li>
</ul>
{% endblock %}

View File

@ -25,14 +25,16 @@ def get_system_config(request):
if request.method == 'POST':
form = SystemConfigForm(request.POST)
if form.is_valid():
config_set('user_registration', form.cleaned_data['user_registration'])
config_set('system_url', form.cleaned_data['system_url'])
config_set('system_welcometext', form.cleaned_data['system_welcometext'])
messages.success(request, _('System settings successfully saved.'))
else:
messages.error(request, _('Please check the form for errors.'))
else:
form = SystemConfigForm(initial={
'user_registration': config_get('user_registration'),
'system_url': config_get('system_url'),
'system_welcometext': config_get('system_welcometext'),
})
return {
'form': form,

View File

@ -259,6 +259,47 @@ def print_userlist(request):
doc.build(story, onFirstPage=firstPage, onLaterPages=laterPages)
return response
def print_passwords(request):
response = HttpResponse(mimetype='application/pdf')
filename = u'filename=%s.pdf;' % _("passwords")
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)]
data= []
system_url = config_get("system_url")
system_welcometext = config_get("system_welcometext")
for user in User.objects.all().order_by('last_name'):
try:
user.get_profile()
cell = []
cell.append(Spacer(0,0.8*cm))
cell.append(Paragraph(_("Your Password for OpenSlides"), stylesheet['Ballot_title']))
cell.append(Paragraph("%s %s %s" % (_("for"), user.first_name, user.last_name), stylesheet['Ballot_subtitle']))
cell.append(Spacer(0,0.5*cm))
cell.append(Paragraph("%s: %s" % (_("Username"), user.username), stylesheet['Ballot_option']))
cell.append(Paragraph("%s: %s" % (_("Password"), user.profile.firstpassword), stylesheet['Ballot_option']))
cell.append(Spacer(0,0.5*cm))
cell.append(Paragraph("%s: %s" % (_("URL"), system_url), stylesheet['Ballot_option']))
cell.append(Spacer(0,0.5*cm))
cell2 = []
cell2.append(Spacer(0,0.8*cm))
cell2.append(Paragraph(system_welcometext.replace('\r\n','<br/>'), stylesheet['Ballot_subtitle']))
data.append([cell,cell2])
except Profile.DoesNotExist:
pass
t=Table(data, 10.5*cm, 7.42*cm)
t.setStyle(TableStyle([ ('LINEBELOW', (0,0), (-1,0), 0.25, colors.grey),
('LINEBELOW', (0,1), (-1,1), 0.25, colors.grey),
('LINEBELOW', (0,1), (-1,-1), 0.25, colors.grey),
('VALIGN', (0,0), (-1,-1), 'TOP'),
]))
story.append(t)
doc.build(story)
return response
def get_application(application, story):
if application.number is None:
story.append(Paragraph(_("Application")+" #[-]", stylesheet['Heading1']))