diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 5bc25477..7772eacc 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -324,6 +324,9 @@ 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()) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 2729592a..e6e158a4 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -2,6 +2,7 @@ import datetime import uuid from itertools import filterfalse +import flask import marshmallow from flask import Response from flask import current_app as app @@ -138,8 +139,12 @@ class DeviceView(View): def one_public(self, id: int): device = Device.query.filter_by(devicehub_id=id, active=True).one() abstract = None + if device.binding: + return flask.redirect(device.public_link) + if device.is_abstract() == 'Twin': abstract = device.placeholder.binding + return render_template( 'devices/layout.html', device=device, states=states, abstract=abstract )