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)