add public link in model

This commit is contained in:
Cayo Puigdefabregas 2022-05-05 12:00:02 +02:00
parent 34f7989553
commit 1023f3fdca
1 changed files with 6 additions and 1 deletions

View File

@ -10,7 +10,7 @@ from typing import Dict, List, Set
from boltons import urlutils from boltons import urlutils
from citext import CIText from citext import CIText
from ereuse_utils.naming import HID_CONVERSION_DOC, Naming from ereuse_utils.naming import HID_CONVERSION_DOC, Naming
from flask import g from flask import g, request
from flask_sqlalchemy import event from flask_sqlalchemy import event
from more_itertools import unique_everseen from more_itertools import unique_everseen
from sqlalchemy import BigInteger, Boolean, Column from sqlalchemy import BigInteger, Boolean, Column
@ -297,6 +297,11 @@ class Device(Thing):
actions.reverse() actions.reverse()
return actions return actions
@property
def public_link(self) -> str:
host_url = request.host_url.strip('/')
return "{}{}".format(host_url, self.url.to_text())
@property @property
def url(self) -> urlutils.URL: def url(self) -> urlutils.URL:
"""The URL where to GET this device.""" """The URL where to GET this device."""