redirect public link from abstract to real device

This commit is contained in:
Cayo Puigdefabregas 2022-08-31 10:55:49 +02:00
parent 4935a1bd75
commit c0653e51ce
2 changed files with 8 additions and 0 deletions

View file

@ -324,6 +324,9 @@ class Device(Thing):
@property @property
def public_link(self) -> str: def public_link(self) -> str:
if self.binding:
return self.binding.device.public_link
host_url = request.host_url.strip('/') host_url = request.host_url.strip('/')
return "{}{}".format(host_url, self.url.to_text()) return "{}{}".format(host_url, self.url.to_text())

View file

@ -2,6 +2,7 @@ import datetime
import uuid import uuid
from itertools import filterfalse from itertools import filterfalse
import flask
import marshmallow import marshmallow
from flask import Response from flask import Response
from flask import current_app as app from flask import current_app as app
@ -138,8 +139,12 @@ class DeviceView(View):
def one_public(self, id: int): def one_public(self, id: int):
device = Device.query.filter_by(devicehub_id=id, active=True).one() device = Device.query.filter_by(devicehub_id=id, active=True).one()
abstract = None abstract = None
if device.binding:
return flask.redirect(device.public_link)
if device.is_abstract() == 'Twin': if device.is_abstract() == 'Twin':
abstract = device.placeholder.binding abstract = device.placeholder.binding
return render_template( return render_template(
'devices/layout.html', device=device, states=states, abstract=abstract 'devices/layout.html', device=device, states=states, abstract=abstract
) )