diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 206cf68b..33867a5d 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -249,6 +249,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix): return schema = SnapshotSchema() schema_lite = Snapshot_lite() + devices = [] self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] for filename, snapshot_json in self.snapshots: 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) db.session.add(response) + devices.append(response.device) if hasattr(response, 'type'): self.result[filename] = 'Ok' @@ -282,7 +284,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix): if commit: db.session.commit() - return self.result + return self.result, devices class NewDeviceForm(FlaskForm): diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 66b28563..70e54de1 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -273,10 +273,12 @@ class UploadSnapshotView(GenericMixView): 'version': __version__, } if form.validate_on_submit(): - snapshot = form.save(commit=False) + # import pdb; pdb.set_trace() + snapshot, devices = form.save(commit=False) if lot_id: 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.commit()