From bdc518b949073892e727177411bfb3d6c1c15830 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 12 Jan 2022 20:26:37 +0100 Subject: [PATCH] fixing create lot id --- ereuse_devicehub/inventory/forms.py | 14 ++++++-------- ereuse_devicehub/inventory/views.py | 4 +--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 701e73a7..ea9a8bc8 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -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 diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 3c9099e7..e8a280f9 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -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)