use populate_obj

This commit is contained in:
Cayo Puigdefabregas 2023-03-07 16:39:52 +01:00
parent 1e62af56a6
commit 0ff2bcae92

View file

@ -141,15 +141,17 @@ class SanitizationEntityForm(FlaskForm):
return True
def save(self, commit=True):
sanitation_data = SanitizationEntity(
logo=URL(self.logo.data),
company_name=self.company_name.data,
location=self.location.data,
responsable_person=self.responsable_person.data,
supervisor_person=self.supervisor_person.data,
user=g.user,
)
if isinstance(self.logo.data, str):
self.logo.data = URL(self.logo.data)
sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first()
if not sanitation_data:
sanitation_data = SanitizationEntity(user_id=g.user.id)
self.populate_obj(sanitation_data)
db.session.add(sanitation_data)
else:
self.populate_obj(sanitation_data)
if commit:
db.session.commit()