1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Only lower if not None

This commit is contained in:
Mo 2022-09-12 19:20:01 +02:00
parent 19819d7e99
commit b1195fff7f
2 changed files with 18 additions and 16 deletions

View file

@ -6,7 +6,7 @@ from flask import flash
from sqlalchemy import select
from . import data_dir
from .exceptions import DataBaseImportException
from .exceptions import DatabaseImportException
from .models import (
Appointment,
Assistant,
@ -42,7 +42,7 @@ def nullable(entry):
def not_nullable(entry):
if is_null(entry):
raise DataBaseImportException("Unnullable entry is NULL!")
raise DatabaseImportException("Unnullable entry is NULL!")
return entry.strip()
@ -54,7 +54,7 @@ def importFromFile(filePath: Path):
db_bk_dir.mkdir(exist_ok=True)
if filePath.name[-4:] != ".txt":
raise DataBaseImportException(
raise DatabaseImportException(
"The import file has to be a text file with txt extension (.txt at the end of the filename)!"
)
@ -82,7 +82,7 @@ def importFromFile(filePath: Path):
if expectingTable:
if line[0] != "#":
raise DataBaseImportException(f"Expected a Table name starting with # but got this line: {line}")
raise DatabaseImportException(f"Expected a Table name starting with # but got this line: {line}")
expectingTable = False
tableName = line[1:]
@ -104,7 +104,7 @@ def importFromFile(filePath: Path):
elif tableName == "Appointment":
activeDict = appointments
else:
raise DataBaseImportException(f"{tableName} is not a valid table name!")
raise DatabaseImportException(f"{tableName} is not a valid table name!")
readHeader = True
continue
@ -122,7 +122,7 @@ def importFromFile(filePath: Path):
cellsLen = len(cells)
if cellsLen != len(activeDict["_header"]):
raise DataBaseImportException(
raise DatabaseImportException(
f"The number of header cells is not equal to the number of row cells in row {cells}!"
)
@ -134,14 +134,14 @@ def importFromFile(filePath: Path):
flash("Semester...")
if len(semesters["label"]) != 1:
raise DataBaseImportException("Only one semester is allowed in an import file!")
raise DatabaseImportException("Only one semester is allowed in an import file!")
semesterLabel = not_nullable(semesters["label"][0])
semesterYear = int(not_nullable(semesters["year"][0]))
dbSemester = get_first(select(Semester).where(Semester.label == semesterLabel, Semester.year == semesterYear))
if dbSemester is None:
raise DataBaseImportException(
raise DatabaseImportException(
f"{semesterLabel}{semesterYear} does not exist in the database! Please make sure that you create the semester from the web interface first."
)
@ -164,7 +164,7 @@ def importFromFile(filePath: Path):
)
if dbPart is None:
raise DataBaseImportException(
raise DatabaseImportException(
f"Part with number {partNumber} and program label {partProgramLabel} does not exist in the database! Please make sure that you create parts from the web interface first."
)
@ -179,7 +179,9 @@ def importFromFile(filePath: Path):
first_name = not_nullable(students["first_name"][i])
last_name = not_nullable(students["last_name"][i])
uni_email = not_nullable(students["uni_email"][i]).lower()
contact_email = nullable(students["contact_email"][i]).lower()
contact_email = nullable(students["contact_email"][i])
if contact_email is not None:
contact_email = contact_email.lower()
bachelor_thesis = nullable(students["bachelor_thesis"][i])
bachelor_thesis_work_group = nullable(students["bachelor_thesis_work_group"][i])
note = nullable(students["note"][i])
@ -277,7 +279,7 @@ def importFromFile(filePath: Path):
if dbExperiment is None:
# TODO: Check if experimentProgram is None
raise DataBaseImportException(
raise DatabaseImportException(
f"Experiment with number {experimentNumber} and program {experimentProgram} does not exist in the database. Please make sure that experiments are created from the web interface."
)
@ -288,7 +290,7 @@ def importFromFile(filePath: Path):
)
if dbSemesterExperiment is None:
raise DataBaseImportException(
raise DatabaseImportException(
f"No semester experiment exists in the database to the experiment with number {experimentNumber} and program {experimentProgram}. Please make sure that semester experiments are created in the web interface. The problem might be that the experiment was not active while creating a new semester"
)
@ -316,7 +318,7 @@ def importFromFile(filePath: Path):
assistant = get_first(select(Assistant).join(User).where(User.email == assistantEmail))
if assistant is None:
raise DataBaseImportException(
raise DatabaseImportException(
f"Assistant with email {assistantEmail} does not exist in the database! Please make sure that you create assistants in the web interface."
)
@ -345,5 +347,5 @@ def importFromFile(filePath: Path):
flash(f"Made a backup of the database after the import at {dest}")
flash("\nImport done!")
flash("Please check that everything worked as expected. Restore the database backup otherwise!")
flash("\nImport done!", "success")
flash("Please check that everything worked as expected. Restore the database backup otherwise!", "warning")

View file

@ -6,5 +6,5 @@ class DatabaseException(Exception):
pass
class DataBaseImportException(Exception):
class DatabaseImportException(Exception):
pass