fixing create lot id

This commit is contained in:
Cayo Puigdefabregas 2022-01-12 20:26:37 +01:00
parent aba5b9dc3b
commit bdc518b949
2 changed files with 7 additions and 11 deletions

View File

@ -54,18 +54,16 @@ class LotForm(FlaskForm):
self.name.data = self.instance.name
def save(self):
name = self.name.data.strip()
if self.instance:
if self.instance.name == name:
return self.instance
self.instance.name = name
else:
self.instance = Lot(name=name)
if not self.id:
self.instance = Lot(name=self.name.data)
self.populate_obj(self.instance)
if not self.id:
self.id = self.instance.id
db.session.add(self.instance)
db.session.commit()
return self.instance
return self.id
db.session.commit()
return self.id

View File

@ -69,12 +69,10 @@ class LotCreateView(View):
title = "Add a new lot"
def dispatch_request(self):
if id:
self.title = "Edit lot"
form = LotForm()
if form.validate_on_submit():
form.save()
next_url = url_for('inventory.devices.lotdevicelist', id=form.instance.id)
next_url = url_for('inventory.devices.lotdevicelist', id=form.id)
return flask.redirect(next_url)
lots = Lot.query.filter(Lot.owner_id == current_user.id)