fix bug upload snapshot from web
This commit is contained in:
parent
388f586f95
commit
089dc92d62
|
@ -249,6 +249,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix):
|
||||||
return
|
return
|
||||||
schema = SnapshotSchema()
|
schema = SnapshotSchema()
|
||||||
schema_lite = Snapshot_lite()
|
schema_lite = Snapshot_lite()
|
||||||
|
devices = []
|
||||||
self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||||
for filename, snapshot_json in self.snapshots:
|
for filename, snapshot_json in self.snapshots:
|
||||||
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
|
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
|
||||||
|
@ -272,6 +273,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix):
|
||||||
|
|
||||||
response = self.build(snapshot_json)
|
response = self.build(snapshot_json)
|
||||||
db.session.add(response)
|
db.session.add(response)
|
||||||
|
devices.append(response.device)
|
||||||
|
|
||||||
if hasattr(response, 'type'):
|
if hasattr(response, 'type'):
|
||||||
self.result[filename] = 'Ok'
|
self.result[filename] = 'Ok'
|
||||||
|
@ -282,7 +284,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix):
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.result
|
return self.result, devices
|
||||||
|
|
||||||
|
|
||||||
class NewDeviceForm(FlaskForm):
|
class NewDeviceForm(FlaskForm):
|
||||||
|
|
|
@ -273,10 +273,12 @@ class UploadSnapshotView(GenericMixView):
|
||||||
'version': __version__,
|
'version': __version__,
|
||||||
}
|
}
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
snapshot = form.save(commit=False)
|
# import pdb; pdb.set_trace()
|
||||||
|
snapshot, devices = form.save(commit=False)
|
||||||
if lot_id:
|
if lot_id:
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
lot.devices.add(snapshot.device)
|
for dev in devices:
|
||||||
|
lot.devices.add(dev)
|
||||||
db.session.add(lot)
|
db.session.add(lot)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
Reference in New Issue