From 1023f3fdcae412b0505eee3863842345bba8be89 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 5 May 2022 12:00:02 +0200 Subject: [PATCH] add public link in model --- ereuse_devicehub/resources/device/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 09451277..c08ec3b8 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -10,7 +10,7 @@ from typing import Dict, List, Set from boltons import urlutils from citext import CIText from ereuse_utils.naming import HID_CONVERSION_DOC, Naming -from flask import g +from flask import g, request from flask_sqlalchemy import event from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column @@ -297,6 +297,11 @@ class Device(Thing): actions.reverse() return actions + @property + def public_link(self) -> str: + 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."""