diff --git a/ereuse_devicehub/api/views.py b/ereuse_devicehub/api/views.py index dd06042c..b4ed2032 100644 --- a/ereuse_devicehub/api/views.py +++ b/ereuse_devicehub/api/views.py @@ -75,7 +75,7 @@ class InventoryView(LoginMixin, SnapshotMixin): self.response = jsonify( { 'url': snapshot.device.url.to_text(), - 'dhid': snapshot.device.devicehub_id, + 'dhid': snapshot.device.dhid, 'sid': snapshot.sid, } ) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 7772eacc..bdf4a654 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -324,16 +324,13 @@ class Device(Thing): @property def public_link(self) -> str: - if self.binding: - return self.binding.device.public_link - host_url = request.host_url.strip('/') return "{}{}".format(host_url, self.url.to_text()) @property def url(self) -> urlutils.URL: """The URL where to GET this device.""" - return urlutils.URL(url_for_resource(Device, item_id=self.devicehub_id)) + return urlutils.URL(url_for_resource(Device, item_id=self.dhid)) @property def rate(self): @@ -618,6 +615,14 @@ class Device(Thing): model = self.model or '' return f'{type} {manufacturer} {model}' + @property + def dhid(self): + if self.placeholder: + return self.placeholder.device.devicehub_id + if self.binding: + return self.binding.device.devicehub_id + return self.devicehub_id + @declared_attr def __mapper_args__(cls): """Defines inheritance. diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 2cc8e65d..2b9530db 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -114,7 +114,7 @@ class Device(Thing): sku = SanitizedStr(description=m.Device.sku.comment) image = URL(description=m.Device.image.comment) allocated = Boolean(description=m.Device.allocated.comment) - devicehub_id = SanitizedStr( + dhid = SanitizedStr( data_key='devicehubID', description=m.Device.devicehub_id.comment )