mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2025-02-13 18:07:43 +00:00
Lower email
This commit is contained in:
parent
a66d95ffb5
commit
19819d7e99
3 changed files with 29 additions and 12 deletions
|
@ -280,6 +280,9 @@ class UserView(SecureAdminModelView):
|
|||
admin = Admin(user=model)
|
||||
self.session.add(admin)
|
||||
|
||||
# Lower email
|
||||
model.email = model.email.lower()
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
if is_created:
|
||||
flash(
|
||||
|
@ -466,10 +469,17 @@ class StudentView(SecureAdminModelView):
|
|||
}
|
||||
|
||||
def on_model_change(self, form, model, is_created):
|
||||
# Don't save contact_email if it is similar to uni_email
|
||||
# No need to strip strings because of email form validation
|
||||
if model.contact_email is not None and model.contact_email == model.uni_email:
|
||||
model.contact_email = None
|
||||
# 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
|
||||
# No need to strip strings because of email form validation
|
||||
if model.contact_email == model.uni_email:
|
||||
model.contact_email = None
|
||||
|
||||
|
||||
def partQueryFactory():
|
||||
|
|
|
@ -37,14 +37,14 @@ def nullable(entry):
|
|||
if is_null(entry):
|
||||
return None
|
||||
|
||||
return entry
|
||||
return entry.strip()
|
||||
|
||||
|
||||
def not_nullable(entry):
|
||||
if is_null(entry):
|
||||
raise DataBaseImportException("Unnullable entry is NULL!")
|
||||
|
||||
return entry
|
||||
return entry.strip()
|
||||
|
||||
|
||||
def importFromFile(filePath: Path):
|
||||
|
@ -178,8 +178,8 @@ def importFromFile(filePath: Path):
|
|||
student_number = int(not_nullable(student_number))
|
||||
first_name = not_nullable(students["first_name"][i])
|
||||
last_name = not_nullable(students["last_name"][i])
|
||||
uni_email = not_nullable(students["uni_email"][i])
|
||||
contact_email = nullable(students["contact_email"][i])
|
||||
uni_email = not_nullable(students["uni_email"][i]).lower()
|
||||
contact_email = nullable(students["contact_email"][i]).lower()
|
||||
bachelor_thesis = nullable(students["bachelor_thesis"][i])
|
||||
bachelor_thesis_work_group = nullable(students["bachelor_thesis_work_group"][i])
|
||||
note = nullable(students["note"][i])
|
||||
|
@ -312,7 +312,7 @@ def importFromFile(filePath: Path):
|
|||
|
||||
for i, date in enumerate(appointments["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))
|
||||
|
||||
if assistant is None:
|
||||
|
|
|
@ -61,9 +61,16 @@ class Student(db.Model):
|
|||
part_students = db.relationship("PartStudent", back_populates="student", lazy=True)
|
||||
|
||||
def __init__(self, uni_email, contact_email=None, **kwargs):
|
||||
# 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():
|
||||
contact_email = None
|
||||
# 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
|
||||
if contact_email == uni_email:
|
||||
contact_email = None
|
||||
|
||||
super().__init__(uni_email=uni_email, contact_email=contact_email, **kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue