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

Lower email

This commit is contained in:
Mo 2022-09-12 19:08:02 +02:00
parent a66d95ffb5
commit 19819d7e99
3 changed files with 29 additions and 12 deletions

View file

@ -280,6 +280,9 @@ class UserView(SecureAdminModelView):
admin = Admin(user=model) admin = Admin(user=model)
self.session.add(admin) self.session.add(admin)
# Lower email
model.email = model.email.lower()
def after_model_change(self, form, model, is_created): def after_model_change(self, form, model, is_created):
if is_created: if is_created:
flash( flash(
@ -466,9 +469,16 @@ class StudentView(SecureAdminModelView):
} }
def on_model_change(self, form, model, is_created): def on_model_change(self, form, model, is_created):
# Lower uni email
model.uni_email = model.uni_email.lower()
if model.contact_email is not None:
# Lower contact email
model.contact_email = model.contact_email.lower()
# Don't save contact_email if it is similar to uni_email # Don't save contact_email if it is similar to uni_email
# No need to strip strings because of email form validation # No need to strip strings because of email form validation
if model.contact_email is not None and model.contact_email == model.uni_email: if model.contact_email == model.uni_email:
model.contact_email = None model.contact_email = None

View file

@ -37,14 +37,14 @@ def nullable(entry):
if is_null(entry): if is_null(entry):
return None return None
return entry return entry.strip()
def not_nullable(entry): def not_nullable(entry):
if is_null(entry): if is_null(entry):
raise DataBaseImportException("Unnullable entry is NULL!") raise DataBaseImportException("Unnullable entry is NULL!")
return entry return entry.strip()
def importFromFile(filePath: Path): def importFromFile(filePath: Path):
@ -178,8 +178,8 @@ def importFromFile(filePath: Path):
student_number = int(not_nullable(student_number)) student_number = int(not_nullable(student_number))
first_name = not_nullable(students["first_name"][i]) first_name = not_nullable(students["first_name"][i])
last_name = not_nullable(students["last_name"][i]) last_name = not_nullable(students["last_name"][i])
uni_email = not_nullable(students["uni_email"][i]) uni_email = not_nullable(students["uni_email"][i]).lower()
contact_email = nullable(students["contact_email"][i]) contact_email = nullable(students["contact_email"][i]).lower()
bachelor_thesis = nullable(students["bachelor_thesis"][i]) bachelor_thesis = nullable(students["bachelor_thesis"][i])
bachelor_thesis_work_group = nullable(students["bachelor_thesis_work_group"][i]) bachelor_thesis_work_group = nullable(students["bachelor_thesis_work_group"][i])
note = nullable(students["note"][i]) note = nullable(students["note"][i])
@ -312,7 +312,7 @@ def importFromFile(filePath: Path):
for i, date in enumerate(appointments["date"]): for i, date in enumerate(appointments["date"]):
date = not_nullable(date) date = not_nullable(date)
assistantEmail = not_nullable(appointments["assistant_email"][i]) assistantEmail = not_nullable(appointments["assistant_email"][i]).lower()
assistant = get_first(select(Assistant).join(User).where(User.email == assistantEmail)) assistant = get_first(select(Assistant).join(User).where(User.email == assistantEmail))
if assistant is None: if assistant is None:

View file

@ -61,8 +61,15 @@ class Student(db.Model):
part_students = db.relationship("PartStudent", back_populates="student", lazy=True) part_students = db.relationship("PartStudent", back_populates="student", lazy=True)
def __init__(self, uni_email, contact_email=None, **kwargs): def __init__(self, uni_email, contact_email=None, **kwargs):
# Lower and strip uni email
uni_email = uni_email.strip().lower()
if contact_email is not None:
# Lower and strip contact email
contact_email = contact_email.strip().lower()
# Don't save contact_email if it is similar to uni_email # Don't save contact_email if it is similar to uni_email
if contact_email is not None and contact_email.strip() == uni_email.strip(): if contact_email == uni_email:
contact_email = None contact_email = None
super().__init__(uni_email=uni_email, contact_email=contact_email, **kwargs) super().__init__(uni_email=uni_email, contact_email=contact_email, **kwargs)