1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-04 22:40:30 +00:00

Fix importing

This commit is contained in:
Mo 2022-09-08 00:33:00 +02:00
parent 45734aa65d
commit fe98376efb
2 changed files with 6 additions and 7 deletions

View file

@ -31,7 +31,7 @@ from wtforms.fields import (
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
from wtforms.widgets import NumberInput
from . import user_datastore
from . import data_dir, user_datastore
from .admin_link_formatters import (
admin_formatter,
appointment_date_formatter,
@ -1282,10 +1282,10 @@ class ImportView(SecureAdminBaseView):
f = form.file.data
filename = secure_filename(f.filename)
directory = "db/import_files"
directory = data_dir / "db/import_files"
Path(directory).mkdir(exist_ok=True)
filePath = directory + f"/{filename}"
filePath = directory / filename
f.save(filePath)
try:
@ -1293,8 +1293,6 @@ class ImportView(SecureAdminBaseView):
except Exception as ex:
flash(str(ex), "error")
return redirect(url_for("main.index"))
return self.render("import.html", form=form)

View file

@ -1,4 +1,5 @@
from datetime import datetime
from pathlib import Path
from shutil import copy2
from flask import flash
@ -46,13 +47,13 @@ def not_nullable(entry):
return entry
def importFromFile(filePath):
def importFromFile(filePath: Path):
db_path = data_dir / "db/advlab.db"
db_bk_dir = db_path.parent / "backups"
db_bk_dir.mkdir(exist_ok=True)
if filePath[-4:] != ".txt":
if filePath.name[-4:] != ".txt":
raise DataBaseImportException(
"The import file has to be a text file with txt extension (.txt at the end of the filename)!"
)