From e7e595f2c2745df78bfbf5157efc92b120396f0b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 23 Jan 2023 19:44:36 +0100 Subject: [PATCH] add json_wb in snapshot --- ereuse_devicehub/inventory/forms.py | 1 + ereuse_devicehub/resources/action/models.py | 12 ++++++++++-- ereuse_devicehub/resources/action/views/snapshot.py | 3 +++ ereuse_devicehub/resources/device/models.py | 8 +++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 1e641f32..d5387f32 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -305,6 +305,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): devices = [] self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] for filename, snapshot_json in self.snapshots: + self.json_wb = copy.copy(snapshot_json) path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) debug = snapshot_json.pop('debug', None) self.version = snapshot_json.get('schema_api') diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index e776fc59..e7cb39b6 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -699,6 +699,12 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice): return json_hw = {} + json_wb = copy.copy(json_wb) + + if json_wb.get('device', {}).get('system_uuid'): + system_uuid = str(json_wb['device']['system_uuid']) + json_wb['device']['system_uuid'] = system_uuid + for k, v in json_wb.items(): if k == 'device': json_hw['device'] = copy.copy(v) @@ -755,8 +761,10 @@ class Snapshot(JoinedWithOneDeviceMixin, ActionWithOneDevice): return snapshots and 'update' or 'new_device' def register_passport_dlt(self): - import pdb; pdb.set_trace() - if 'trublo' not in app.blueprints.keys() or not self.hid: + import pdb + + pdb.set_trace() + if 'trublo' not in app.blueprints.keys() or not self.device.hid: return if not session.get('token_dlt'): diff --git a/ereuse_devicehub/resources/action/views/snapshot.py b/ereuse_devicehub/resources/action/views/snapshot.py index bd01a768..a9a689bc 100644 --- a/ereuse_devicehub/resources/action/views/snapshot.py +++ b/ereuse_devicehub/resources/action/views/snapshot.py @@ -1,5 +1,6 @@ """ This is the view for Snapshots """ +import copy import json import os import shutil @@ -121,6 +122,7 @@ class SnapshotMixin: snapshot.device.set_hid() snapshot.device.binding.device.set_hid() + snapshot.create_json_hw(self.json_wb) snapshot.device.register_dlt() snapshot.register_passport_dlt() @@ -214,6 +216,7 @@ class SnapshotView(SnapshotMixin): self.schema = schema self.resource_def = resource_def self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] + self.json_wb = copy.copy(snapshot_json) self.path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) self.version = snapshot_json.get('version') self.uuid = snapshot_json.get('uuid') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index d1a0ccec..da7a3776 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -777,10 +777,6 @@ class Device(Thing): ).first() def set_hid(self): - with suppress(TypeError): - self.hid = Naming.hid( - self.type, self.manufacturer, self.model, self.serial_number - ) if 'property_hid' in app.blueprints.keys(): try: from modules.device.utils import set_hid @@ -887,7 +883,9 @@ class Device(Thing): return types.get(self.type, '') def register_dlt(self): - import pdb; pdb.set_trace() + import pdb + + pdb.set_trace() if 'trublo' not in app.blueprints.keys() or not self.hid: return