From 94a586f00b6d6f07ca6dd6c24c89f858b6301f1a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 2 Dec 2022 10:08:03 +0100 Subject: [PATCH] filter correct values --- ereuse_devicehub/resources/device/models.py | 17 +++++++++-------- ereuse_devicehub/resources/device/schemas.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 61e8cae7..a983643b 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -747,13 +747,13 @@ class Device(Thing): def set_hid(self): """ - # product_vendor, - # product_family, - # product_chassis, - # product_number, + # product_vendor, is a manufacturer + # product_family, is a model but from dmidecode + # product_chassis, is a type of chassis + # product_number, is a ?? # product_version, # product_sku, - # product_serial, + # product_serial, is a serial number # product_uuid, # board_vendor, # board_number, @@ -762,6 +762,8 @@ class Device(Thing): """ with suppress(TypeError): family = (self.family or '').replace(' ', '_') + model = ((self.model or '').replace(' ', '_'),) + model = model or family chassis = self.type if hasattr(self, 'chassis'): chassis = self.chassis and self.chassis.name or '' @@ -792,12 +794,11 @@ class Device(Thing): self.hid = '-'.join( [ (self.manufacturer or '').replace(' ', '_'), - family, + model, chassis, - (self.model or '').replace(' ', '_'), + self.serial_number, version, sku, - self.serial_number, system_uuid, board_manufacturer, board_model, diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 76a1fee2..604da213 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -208,6 +208,21 @@ class Computer(Device): receiver_id = UUID(data_key='receiverID') system_uuid = UUID(required=False) + @post_load + def validate_hid(self, data): + """Validates than exist model manufacturer and system_uuid.""" + + minimum = [ + data['manufacturer'], + data['model'], + data['system_uuid'], + ] + + if not all(minimum): + txt = 'You can not register one device with out minimum datas, ' + txt += 'you can to do one placeholder.' + raise ValidationError(txt) + class Desktop(Computer): __doc__ = m.Desktop.__doc__