From 4f6a7b44ab8e93206704b1d57518c4e30759826d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 17 May 2023 19:26:23 +0200 Subject: [PATCH] fixed udslink for django 4.x --- server/src/uds/core/util/html.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/src/uds/core/util/html.py b/server/src/uds/core/util/html.py index 0bbe7f91b..3d5603268 100644 --- a/server/src/uds/core/util/html.py +++ b/server/src/uds/core/util/html.py @@ -43,12 +43,14 @@ logger = logging.getLogger(__name__) def udsLink(request: 'HttpRequest', ticket: str, scrambler: str) -> str: - if request.is_secure(): - proto = 'udss' - else: - proto = 'uds' + # Removed http support, so only udss:// links are generated - return f'{proto}://{request.build_absolute_uri("/")}{ticket}/{scrambler}' + # If we have a scheme, remove it + rels = request.build_absolute_uri("/").split("://", maxsplit=1) + rel = rels[1] if len(rels) > 1 else rels[0] + + # Ensure that build_absolute_uri returns a valid url without scheme + return f'udss://{rel}{ticket}/{scrambler}' def udsAccessLink( @@ -67,10 +69,7 @@ def parseDate(dateToParse) -> datetime.date: date_format = '%d/%m/%Y' else: date_format = ( - formats.get_format('SHORT_DATE_FORMAT') - .replace('Y', '%Y') - .replace('m', '%m') - .replace('d', '%d') + formats.get_format('SHORT_DATE_FORMAT').replace('Y', '%Y').replace('m', '%m').replace('d', '%d') ) # pylint: disable=maybe-no-member return datetime.datetime.strptime(dateToParse, date_format).date()