This commit is contained in:
2024-01-29 21:43:35 +00:00
parent 327b84d137
commit c16bcb9291
3 changed files with 10 additions and 62 deletions

View File

@@ -85,11 +85,7 @@ def ep_create_new_pad(pad_id, text="helloworld"):
return None return None
if ep_pad_exists(pad_id) is False: if ep_pad_exists(pad_id) is False:
ep_c.createGroupPad( ep_c.createGroupPad(groupID=ep_group["groupID"], padName=pad_id, text=text)
groupID=ep_group["groupID"],
padName=pad_id,
text=text
)
logger.info("Neues Etherpad '%s' erzeugt.", pad_id) logger.info("Neues Etherpad '%s' erzeugt.", pad_id)
return pad_id return pad_id

View File

@@ -36,7 +36,7 @@ def _create_ep_session(request, expires):
def add_ep_cookie(request, response): def add_ep_cookie(request, response):
expires = timezone.now() + timedelta(hours=3) 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( response.set_cookie(
"sessionID", "sessionID",
ep_session, ep_session,
@@ -44,12 +44,7 @@ def add_ep_cookie(request, response):
domain=settings.HOST_NAME, domain=settings.HOST_NAME,
path="/", path="/",
) )
response.set_cookie( response.set_cookie("sessionID", ep_session, expires=expires, path="/etherpad")
"sessionID",
ep_session,
expires=expires,
path="/etherpad"
)
return response return response

View File

@@ -12,7 +12,7 @@ def generate_pdf(wiref):
if wiref is not None and wiref.status == Wiref.Status.OPENED: if wiref is not None and wiref.status == Wiref.Status.OPENED:
bills = Bill.objects.filter(wiref=wiref).order_by("date") bills = Bill.objects.filter(wiref=wiref).order_by("date")
# get data for pdf # Get data for pdf
data = {} data = {}
for count, elem in enumerate(bills): for count, elem in enumerate(bills):
data.update( data.update(
@@ -20,19 +20,19 @@ def generate_pdf(wiref):
f"Datum.{count}": str(elem.date.strftime("%d.%m.%Y")), f"Datum.{count}": str(elem.date.strftime("%d.%m.%Y")),
f"Aussteller.{count}": elem.invoice, f"Aussteller.{count}": elem.invoice,
f"Verwendungszweck.{count}": elem.purpose, f"Verwendungszweck.{count}": elem.purpose,
# replace decimal separator from '.' to ',' # Replace decimal separator from '.' to ','
f"Betrag.{count}": str(elem.amount).replace(".", ","), f"Betrag.{count}": str(elem.amount).replace(".", ","),
} }
) )
# get budget year # Get budget year
today = datetime.date.today() today = datetime.date.today()
if today.month < 7: if today.month < 7:
budget_year = f"{today.year - 1}-{today.year}" budget_year = f"{today.year - 1}-{today.year}"
else: else:
budget_year = f"{today.year}-{today.year + 1}" 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 total = 0
for elem in bills: for elem in bills:
total += elem.amount total += elem.amount
@@ -41,12 +41,12 @@ def generate_pdf(wiref):
{ {
"Laufende Nummer": str(wiref.wiref_id), "Laufende Nummer": str(wiref.wiref_id),
"Budgetjahr": budget_year, "Budgetjahr": budget_year,
# replace decimal separator from '.' to ',' # Replace decimal separator from '.' to ','
"Summe": str(total).replace(".", ","), "Summe": str(total).replace(".", ","),
} }
) )
# write data in pdf # Write data in pdf
pdf_path = os.path.join(os.path.dirname(__file__), "static/Vorlage.pdf") pdf_path = os.path.join(os.path.dirname(__file__), "static/Vorlage.pdf")
reader = PdfReader(pdf_path) reader = PdfReader(pdf_path)
writer = PdfWriter() writer = PdfWriter()
@@ -60,52 +60,9 @@ def generate_pdf(wiref):
with io.BytesIO() as bytes_stream: with io.BytesIO() as bytes_stream:
writer.write(bytes_stream) writer.write(bytes_stream)
# Save pdf in wiref
wiref_name = f"Abrechnungsformular-{wiref.wiref_id}.pdf" wiref_name = f"Abrechnungsformular-{wiref.wiref_id}.pdf"
wiref.file_field.save(wiref_name, File(bytes_stream, wiref_name)) 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 return True