From c16bcb9291a46fc8d0f2950b5ef93a8a2db79817 Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Mon, 29 Jan 2024 21:43:35 +0000 Subject: [PATCH] black --- fet2020/documents/api.py | 6 +--- fet2020/documents/etherpadlib.py | 9 ++--- fet2020/finance/utils.py | 57 ++++---------------------------- 3 files changed, 10 insertions(+), 62 deletions(-) diff --git a/fet2020/documents/api.py b/fet2020/documents/api.py index bff3e74b..1279eae4 100644 --- a/fet2020/documents/api.py +++ b/fet2020/documents/api.py @@ -85,11 +85,7 @@ def ep_create_new_pad(pad_id, text="helloworld"): return None if ep_pad_exists(pad_id) is False: - ep_c.createGroupPad( - groupID=ep_group["groupID"], - padName=pad_id, - text=text - ) + ep_c.createGroupPad(groupID=ep_group["groupID"], padName=pad_id, text=text) logger.info("Neues Etherpad '%s' erzeugt.", pad_id) return pad_id diff --git a/fet2020/documents/etherpadlib.py b/fet2020/documents/etherpadlib.py index 4438d485..6bfeb894 100644 --- a/fet2020/documents/etherpadlib.py +++ b/fet2020/documents/etherpadlib.py @@ -36,7 +36,7 @@ def _create_ep_session(request, expires): def add_ep_cookie(request, response): expires = timezone.now() + timedelta(hours=3) - if (ep_session := _create_ep_session(request, expires)): + if ep_session := _create_ep_session(request, expires): response.set_cookie( "sessionID", ep_session, @@ -44,12 +44,7 @@ def add_ep_cookie(request, response): domain=settings.HOST_NAME, path="/", ) - response.set_cookie( - "sessionID", - ep_session, - expires=expires, - path="/etherpad" - ) + response.set_cookie("sessionID", ep_session, expires=expires, path="/etherpad") return response diff --git a/fet2020/finance/utils.py b/fet2020/finance/utils.py index 4764e921..b3b64b7e 100644 --- a/fet2020/finance/utils.py +++ b/fet2020/finance/utils.py @@ -12,7 +12,7 @@ def generate_pdf(wiref): if wiref is not None and wiref.status == Wiref.Status.OPENED: bills = Bill.objects.filter(wiref=wiref).order_by("date") - # get data for pdf + # Get data for pdf data = {} for count, elem in enumerate(bills): data.update( @@ -20,19 +20,19 @@ def generate_pdf(wiref): f"Datum.{count}": str(elem.date.strftime("%d.%m.%Y")), f"Aussteller.{count}": elem.invoice, f"Verwendungszweck.{count}": elem.purpose, - # replace decimal separator from '.' to ',' + # Replace decimal separator from '.' to ',' f"Betrag.{count}": str(elem.amount).replace(".", ","), } ) - # get budget year + # Get budget year today = datetime.date.today() if today.month < 7: budget_year = f"{today.year - 1}-{today.year}" else: budget_year = f"{today.year}-{today.year + 1}" - # get total of all bills of wiref form + # Get total of all bills of wiref form total = 0 for elem in bills: total += elem.amount @@ -41,12 +41,12 @@ def generate_pdf(wiref): { "Laufende Nummer": str(wiref.wiref_id), "Budgetjahr": budget_year, - # replace decimal separator from '.' to ',' + # Replace decimal separator from '.' to ',' "Summe": str(total).replace(".", ","), } ) - # write data in pdf + # Write data in pdf pdf_path = os.path.join(os.path.dirname(__file__), "static/Vorlage.pdf") reader = PdfReader(pdf_path) writer = PdfWriter() @@ -60,52 +60,9 @@ def generate_pdf(wiref): with io.BytesIO() as bytes_stream: writer.write(bytes_stream) + # Save pdf in wiref wiref_name = f"Abrechnungsformular-{wiref.wiref_id}.pdf" wiref.file_field.save(wiref_name, File(bytes_stream, wiref_name)) - ''' - with fitz.open(pdf_path) as doc: - for page in doc: - widgets = page.widgets() - for widget in widgets: - if widget.field_name in data: - # removing '\r' is important for textbox in pdf file - widget.field_value = data[widget.field_name].replace("\r", "") - fontsize = widget.text_fontsize - - # update font size if there are more than one newlines in string - count = widget.field_value.count("\n") + 1 - if count > 1: - fontsize = 0.7 * widget.rect.height / count - - if ( - widget.text_fontsize == 0 - or fontsize < widget.text_fontsize - ): - widget.text_fontsize = fontsize - - # get max length of one line of multi-line text - max_len = 0 - for elem in widget.field_value.split("\n"): - length = fitz.get_text_length(elem) - if length > max_len: - max_len = length - - # update fontsize if length of text is longer than rectangle width - if max_len > widget.rect.width: - fontsize = widget.rect.width / max_len * 10 - - if ( - widget.text_fontsize == 0 - or fontsize < widget.text_fontsize - ): - widget.text_fontsize = fontsize - - widget.update() - - dist = doc.tobytes() - wiref_name = f"{wiref.wiref_id}.pdf" - wiref.file_field.save(wiref_name, File(io.BytesIO(dist), wiref_name)) - ''' return True