fix bug
This commit is contained in:
parent
83ea86705d
commit
26b322ba70
|
@ -335,6 +335,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
screen = FloatField('Screen size', [validators.Optional()])
|
screen = FloatField('Screen size', [validators.Optional()])
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.objs = set()
|
||||||
self._obj = kwargs.pop('_obj', None)
|
self._obj = kwargs.pop('_obj', None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
if self._obj:
|
if self._obj:
|
||||||
|
@ -545,6 +546,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
type="New device", source='Web form', placeholder=device.placeholder
|
type="New device", source='Web form', placeholder=device.placeholder
|
||||||
)
|
)
|
||||||
db.session.add(placeholder_log)
|
db.session.add(placeholder_log)
|
||||||
|
self.objs.add(device)
|
||||||
|
|
||||||
def reset_ids(self):
|
def reset_ids(self):
|
||||||
if self.amount.data > 1:
|
if self.amount.data > 1:
|
||||||
|
|
|
@ -257,15 +257,14 @@ class DeviceCreateView(GenericMixin):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
snapshot = form.save(commit=False)
|
form.save(commit=False)
|
||||||
next_url = url_for('inventory.devicelist')
|
next_url = url_for('inventory.devicelist')
|
||||||
if lot_id:
|
if lot_id:
|
||||||
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
||||||
if snapshot and snapshot.device:
|
if form.objs:
|
||||||
lots = self.context['lots']
|
lots = self.context['lots']
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
lot.devices.add(snapshot.device)
|
lot.devices = lot.devices.union(form.objs)
|
||||||
db.session.add(lot)
|
|
||||||
else:
|
else:
|
||||||
messages.error('Sorry, the device could not be created')
|
messages.error('Sorry, the device could not be created')
|
||||||
|
|
||||||
|
|
Reference in New Issue