fix(members/excel): normalize filename of generated vbk form

pull/137/head
Christian Merten 10 months ago
parent 7b64f48ad7
commit 54ed4c85e4
Signed by: christian.merten
GPG Key ID: D953D69721B948B3

@ -4,6 +4,7 @@ import xlsxwriter
import openpyxl
from django.conf import settings
from contrib.media import media_path, find_template
from utils import normalize_filename
from .models import WEEKDAYS, LJPProposal
def generate_group_overview(all_groups, limit_to_public = True):
@ -126,6 +127,7 @@ def generate_ljp_vbk(excursion):
if hasattr(excursion, 'statement'):
sheet['Q19'] = f"{excursion.statement.total_theoretic}"
filename = f"{excursion.code}_{title}_LJP_V-BK_3.{excursion.ljpproposal.category}.xlsx"
name = normalize_filename(f"{excursion.code}_{title}_LJP_V-BK_3.{excursion.ljpproposal.category}")
filename = name + ".xlsx"
workbook.save(media_path(filename))
return filename

@ -12,6 +12,7 @@ from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect
from wsgiref.util import FileWrapper
from contrib.media import media_path, media_dir, serve_media, ensure_media_dir, find_template
from utils import normalize_filename
from PIL import Image
@ -20,10 +21,7 @@ def serve_pdf(filename_pdf):
def generate_tex(name, template_path, context):
filename = name + "_" + datetime.today().strftime("%d_%m_%Y")
filename = filename.replace(' ', '_').replace('&', '').replace('/', '_')
# drop umlauts, accents etc.
filename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').decode()
filename = normalize_filename(name)
filename_tex = filename + '.tex'
tmpl = get_template(template_path)
@ -76,10 +74,7 @@ def render_tex(name, template_path, context, save_only=False):
def fill_pdf_form(name, template_path, fields, attachments=[], save_only=False):
filename = name + "_" + datetime.today().strftime("%d_%m_%Y")
filename = filename.replace(' ', '_').replace('&', '').replace('/', '_')
# drop umlauts, accents etc.
filename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').decode()
filename = normalize_filename(name)
filename_pdf = filename + '.pdf'
path = find_template(template_path)
@ -122,9 +117,7 @@ def merge_pdfs(name, filenames, save_only=False):
for pdf in filenames:
merger.append(media_path(pdf))
filename = name + "_" + datetime.today().strftime("%d_%m_%Y")
filename = filename.replace(' ', '_').replace('&', '').replace('/', '_')
filename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').decode()
filename = normalize_filename(name)
filename_pdf = filename + ".pdf"
merger.write(media_path(filename_pdf))
merger.close()

@ -1,3 +1,4 @@
from datetime import datetime
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
@ -69,3 +70,11 @@ def normalize_name(raw, nospaces=True, noumlaut=True):
if nospaces:
raw = raw.replace(' ', '_')
return unicodedata.normalize('NFKD', raw).encode('ascii', 'ignore').decode('ascii')
def normalize_filename(filename, append_date=True):
if append_date:
filename = filename + "_" + datetime.today().strftime("%d_%m_%Y")
filename = filename.replace(' ', '_').replace('&', '').replace('/', '_')
# drop umlauts, accents etc.
return unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore').decode()

Loading…
Cancel
Save