From 09a0557e4f5634c5d7442572847166fcb8486e69 Mon Sep 17 00:00:00 2001 From: Doug Le Tough Date: Wed, 9 May 2018 10:53:04 +0200 Subject: [PATCH] "list staffers pdf" --- participate.py | 130 +++++++++++++++++++++++++++++++++- templates/list_users_txt.html | 2 +- 2 files changed, 129 insertions(+), 3 deletions(-) diff --git a/participate.py b/participate.py index 9bfdb35..623fe6e 100755 --- a/participate.py +++ b/participate.py @@ -1063,8 +1063,134 @@ def print_users(): page = str(request.url_rule) menu = get_menu(page) staffers = Tetawebapp_users.query.filter(Tetawebapp_users.is_admin==0, Tetawebapp_users.link_id==None).order_by(Tetawebapp_users.name).all() - data = render_template('list_users_txt.html', staffers=staffers) - return data + #~ data = render_template('list_users_txt.html', staffers=staffers) + + + #~ data = [line for line in data.split('\n') if len(line) > 0] + #~ data = '\n'.join(data) + #~ data = [line for line in data.split('",\n') if len(line) > 0] + #~ data = '", '.join(data) + #~ ddata = [ast.literal_eval(line) for line in data.split('\n')] + pdf = cStringIO.StringIO() + doc = SimpleDocTemplate(pdf, pagesize=A4, rightMargin=3,leftMargin=3, topMargin=3,bottomMargin=3) + elements = [] + styles = getSampleStyleSheet() + styles.add(ParagraphStyle(name='master_title', + alignment=TA_LEFT, + fontSize=20, + leading=25, + spaceBefore=10, + spaceAfter=10, + )) + styles.add(ParagraphStyle(name='day_title', + alignment=TA_LEFT, + backColor=orange, + borderWidth=1, + borderColor=black, + borderPadding=5, + spaceBefore=10, + spaceAfter=10 + )) + styles.add(ParagraphStyle(name='role_title', + alignment=TA_LEFT, + backColor=lightsalmon, + borderWidth=1, + borderColor=black, + borderPadding=5, + spaceBefore=10, + spaceAfter=10 + )) + styles.add(ParagraphStyle(name='turn', + alignment=TA_LEFT, + backColor=white, + borderWidth=1, + borderColor=black, + borderPadding=5, + spaceBefore=10, + spaceAfter=0 + )) + styles.add(ParagraphStyle(name='basic_text', + alignment=TA_LEFT, + spaceBefore=5, + spaceAfter=5 + )) + styles.add(ParagraphStyle(name='row1', + alignment=TA_LEFT, + backColor=white, + spaceBefore=10, + spaceAfter=10 + )) + styles.add(ParagraphStyle(name='row2', + alignment=TA_CENTER, + backColor=white, + spaceBefore=10, + spaceAfter=10 + )) + + + for staffer in staffers: + rows = [] + row = Paragraph(staffer[1], styles['row2']), staffer[2], styles['row2']), staffer[3], styles['row2'])) + table = Table(rows, colWidths=cols_width, rowHeights=23) + rows.append(row) + table = Table(rows, colWidths=cols_width, rowHeights=23) + table.setStyle(TableStyle( [('GRID', (0,0), (-1,-1), 0.25, colors.black), + ('ALIGN', (1,1), (-1,-1), 'RIGHT')])) + elements.append(table) + + + #~ wday = day[0] + #~ day_turns = day[1] + #~ cur_role = '' + #~ if wday not in ['Mardi', 'Mercredi']: + #~ elements.append(PageBreak()) + #~ elements.append(Paragraph("%s" % wday, styles['day_title'])) + #~ for turn in day_turns: + #~ rows = [] + #~ role = turn[1] + #~ start_time = turn[0].start_time + #~ end_time = turn[0].end_time + #~ num_slot = turn[0].num_slot + #~ role_id = turn[0].role_id + #~ turn_id = turn[0].id + #~ if role != cur_role: + #~ cur_role = role + #~ elements.append(Paragraph("%s" % role, styles['role_title'])) + #~ row = (Paragraph("%s / %s" % (start_time.strftime('%HH%M'), end_time.strftime('%HH%M')), styles['row1']),) + #~ for slot in range(0, num_slot): + #~ cols_width = [100] + [485/num_slot] * num_slot + #~ allocated_slot = [] + #~ for sslot in staffs: + #~ if sslot[0].turn_id == turn_id and sslot[0].slot_num == slot: + #~ allocated_slot.append(sslot[0].slot_num) + #~ row += (Paragraph(sslot[1], styles['row2']),) + #~ if slot not in allocated_slot: + #~ row += (Paragraph(" ", styles['row2']),) + #~ rows.append(row) + #~ table = Table(rows, colWidths=cols_width, rowHeights=23) + #~ table.setStyle(TableStyle( [('GRID', (0,0), (-1,-1), 0.25, colors.black), + #~ ('ALIGN', (1,1), (-1,-1), 'RIGHT')])) + #~ elements.append(table) + styles.wordWrap = 'CJK' + doc.build(elements) + pdf_out = pdf.getvalue() + pdf.close() + response = app.make_response(pdf_out) + response.headers['Content-Disposition'] = "attachment; filename=feuille_staff_thsf.pdf" + response.mimetype = 'application/pdf' + return response + + + + + + + + + + + + # User is not admin return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide") except Exception as e: diff --git a/templates/list_users_txt.html b/templates/list_users_txt.html index 2a0255c..3ca7fac 100644 --- a/templates/list_users_txt.html +++ b/templates/list_users_txt.html @@ -1,3 +1,3 @@ {% for staffer in staffers %} -{{staffer.name}},{{staffer.phone}},{{staffer.mail}},{{staffer.diet}}"\n" +{{staffer.name}},{{staffer.phone}},{{staffer.mail}},{{staffer.diet}} {% endfor %}