add message with result when a devices is add or remove of a lot
This commit is contained in:
parent
6389956adc
commit
15d913efea
|
@ -46,9 +46,11 @@ class LotDeviceForm(FlaskForm):
|
|||
return False
|
||||
|
||||
self._lot = (
|
||||
Lot.query.filter(Lot.id == self.lot.data)
|
||||
.filter(Lot.owner_id == g.user.id)
|
||||
.one()
|
||||
Lot.query.outerjoin(Trade)
|
||||
.filter(Lot.id == self.lot.data)
|
||||
.filter(or_(Trade.user_from == g.user,
|
||||
Trade.user_to == g.user,
|
||||
Lot.owner_id == g.user.id)).one()
|
||||
)
|
||||
|
||||
devices = set(self.devices.data.split(","))
|
||||
|
@ -68,14 +70,16 @@ class LotDeviceForm(FlaskForm):
|
|||
if trade not in dev.actions:
|
||||
trade.devices.add(dev)
|
||||
|
||||
self._lot.devices.update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
if self._devices:
|
||||
self._lot.devices.update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
|
||||
def remove(self):
|
||||
self._lot.devices.difference_update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
if self._devices:
|
||||
self._lot.devices.difference_update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
class LotForm(FlaskForm):
|
||||
|
|
|
@ -135,9 +135,14 @@ class LotDeviceAddView(View):
|
|||
form = LotDeviceForm()
|
||||
if form.validate_on_submit():
|
||||
form.save()
|
||||
messages.success(
|
||||
'Add devices to lot "{}" successfully!'.format(form._lot.name)
|
||||
)
|
||||
else:
|
||||
messages.error('Error adding devices to lot!')
|
||||
|
||||
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||
return flask.redirect(next_url)
|
||||
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||
return flask.redirect(next_url)
|
||||
|
||||
|
||||
class LotDeviceDeleteView(View):
|
||||
|
@ -149,9 +154,14 @@ class LotDeviceDeleteView(View):
|
|||
form = LotDeviceForm()
|
||||
if form.validate_on_submit():
|
||||
form.remove()
|
||||
messages.success(
|
||||
'Remove devices from lot "{}" successfully!'.format(form._lot.name)
|
||||
)
|
||||
else:
|
||||
messages.error('Error removing devices from lot!')
|
||||
|
||||
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||
return flask.redirect(next_url)
|
||||
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||
return flask.redirect(next_url)
|
||||
|
||||
|
||||
class LotCreateView(View):
|
||||
|
|
Reference in New Issue