From c4e2178c03fd684a1a3dae935f8ba22ac02601f4 Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 6 Nov 2023 15:19:03 +0100 Subject: [PATCH] =?UTF-8?q?Glemte=20=C3=A5=20legge=20til=20pdf.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otime/pdf.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/otime/pdf.py b/otime/pdf.py index ab57854..b4c0bdb 100644 --- a/otime/pdf.py +++ b/otime/pdf.py @@ -1,22 +1,31 @@ +import datetime from fpdf import FPDF -def create_start_list(event, file_path): +def create_result_list(event, file_path, o_classes=[]): + results = event.get_result(o_classes) + pdf = FPDF() - pdf.add_page() pdf.add_font("LiberationSans", fname="../../otime/data/fonts/LiberationSans-Regular.ttf") pdf.set_font("LiberationSans", size=10) line_height = pdf.font_size * 1.5 col_width = pdf.epw / 4 # distribute content evenly - for runner in event.runners: - pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L') - pdf.multi_cell(col_width, line_height, runner.o_class, border=1, ln=3, max_line_height=pdf.font_size) - pdf.multi_cell(col_width, line_height, str(runner.card_id), border=1, ln=3, max_line_height=pdf.font_size) - if runner.start_time is not None: - pdf.multi_cell(col_width, line_height, str(runner.start_time), border=1, ln=3, max_line_height=pdf.font_size) - else: - pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size) + + for class_result in results: + pdf.write(txt=class_result.name) pdf.ln(line_height) + for runner in class_result.runner_results: + if runner.status == 'OK': + pdf.multi_cell(col_width, line_height, str(runner.place), border=1, ln=3, max_line_height=pdf.font_size, align='L') + else: + pdf.multi_cell(col_width, line_height, runner.status, border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L') + pdf.multi_cell(col_width, line_height, runner.club, border=1, ln=3, max_line_height=pdf.font_size) + if runner.status == 'OK': + pdf.multi_cell(col_width, line_height, str(datetime.timedelta(seconds = runner.total_time)), border=1, ln=3, max_line_height=pdf.font_size) + else: + pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size) + pdf.ln(line_height) pdf.output(file_path) def create_all_invoices(self, filename_prefix):