adding edit lot and fix bug of session.commit
This commit is contained in:
parent
18fead559c
commit
483f674957
|
@ -44,10 +44,10 @@ class LotForm(FlaskForm):
|
||||||
name = StringField(u'Name', [validators.length(min=1)])
|
name = StringField(u'Name', [validators.length(min=1)])
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
id = kwargs.pop('id', None)
|
self.id = kwargs.pop('id', None)
|
||||||
self.instance = None
|
self.instance = None
|
||||||
if id:
|
if self.id:
|
||||||
self.instance = Lot.query.filter(Lot.id == id).filter(
|
self.instance = Lot.query.filter(Lot.id == self.id).filter(
|
||||||
Lot.owner_id == g.user.id).one()
|
Lot.owner_id == g.user.id).one()
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
if self.instance and not self.name.data:
|
if self.instance and not self.name.data:
|
||||||
|
@ -62,9 +62,13 @@ class LotForm(FlaskForm):
|
||||||
else:
|
else:
|
||||||
self.instance = Lot(name=name)
|
self.instance = Lot(name=name)
|
||||||
|
|
||||||
db.session.add(self.instance)
|
if not self.id:
|
||||||
|
db.session.add(self.instance)
|
||||||
|
db.session.commit()
|
||||||
|
return self.instance
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.instance
|
return self.id
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
if self.instance and not self.instance.devices:
|
if self.instance and not self.instance.devices:
|
||||||
|
|
|
@ -73,8 +73,11 @@ class LotView(View):
|
||||||
self.title = "Edit lot"
|
self.title = "Edit lot"
|
||||||
form = LotForm(id=id)
|
form = LotForm(id=id)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
lot = form.save()
|
form.save()
|
||||||
next_url = url_for('inventory.devices.lotdevicelist', id=lot.id)
|
lot_id = id
|
||||||
|
if not id:
|
||||||
|
lot_id = form.instance.id
|
||||||
|
next_url = url_for('inventory.devices.lotdevicelist', id=lot_id)
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
return flask.render_template(self.template_name, form=form, title=self.title)
|
return flask.render_template(self.template_name, form=form, title=self.title)
|
||||||
|
|
|
@ -28,6 +28,17 @@
|
||||||
|
|
||||||
<div class="col-xl-12">
|
<div class="col-xl-12">
|
||||||
|
|
||||||
|
{% if lot %}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body pt-3">
|
||||||
|
<!-- Bordered Tabs -->
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<h3><a href="{{ url_for('inventory.devices.lot_edit', id=lot.id) }}">{{ lot.name }}</a></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body pt-3">
|
<div class="card-body pt-3">
|
||||||
<!-- Bordered Tabs -->
|
<!-- Bordered Tabs -->
|
||||||
|
|
Reference in New Issue