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

contact_email only when different also in forms

This commit is contained in:
Mo 2022-09-08 01:12:13 +02:00
parent aca41ede47
commit 93fef08b4c
2 changed files with 8 additions and 1 deletions

View file

@ -482,6 +482,12 @@ class StudentView(SecureAdminModelView):
"part_students": part_students_export_formatter, "part_students": part_students_export_formatter,
} }
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
def partQueryFactory(): def partQueryFactory():
return Part.query.where(Part.semester == current_user.active_semester) return Part.query.where(Part.semester == current_user.active_semester)

View file

@ -61,7 +61,8 @@ 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):
if contact_email is not None and uni_email.strip() == contact_email.strip(): # 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 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)