mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-04 22:40:30 +00:00
contact_email only when different also in forms
This commit is contained in:
parent
aca41ede47
commit
93fef08b4c
2 changed files with 8 additions and 1 deletions
|
@ -482,6 +482,12 @@ class StudentView(SecureAdminModelView):
|
|||
"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():
|
||||
return Part.query.where(Part.semester == current_user.active_semester)
|
||||
|
|
|
@ -61,7 +61,8 @@ class Student(db.Model):
|
|||
part_students = db.relationship("PartStudent", back_populates="student", lazy=True)
|
||||
|
||||
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
|
||||
|
||||
super().__init__(uni_email=uni_email, contact_email=contact_email, **kwargs)
|
||||
|
|
Loading…
Reference in a new issue