use dhid for get the devicehub_id of the real parth of a device
This commit is contained in:
parent
a222b37ecc
commit
60f7ee8354
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
Reference in New Issue