From d04216ad795f0c8d84c542b7787621c1dab54fa0 Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 15 Oct 2024 13:09:34 +0200 Subject: [PATCH] api snapshot public_url bugfix with the following code the URL is more appropriate (it basically mirrors the user's request) before: http://localhost/device/{shortid} after http://localhost:8000/device/{shortid} --- api/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/api/views.py b/api/views.py index 175fe3e..fe68079 100644 --- a/api/views.py +++ b/api/views.py @@ -1,6 +1,5 @@ import json -from django.conf import settings from django.urls import reverse_lazy from django.shortcuts import get_object_or_404, redirect from django.utils.translation import gettext_lazy as _ @@ -82,15 +81,14 @@ def NewSnapshot(request): if not annotation: return JsonResponse({'status': 'fail'}, status=200) - url = "{}://{}{}".format( - request.scheme, - settings.DOMAIN, - reverse_lazy("device:details", args=(annotation.value,)) - ) + url_args = reverse_lazy("device:details", args=(annotation.value,)) + url = request.build_absolute_uri(url_args) + response = { "status": "success", "dhid": annotation.value[:6].upper(), "url": url, + # TODO replace with public_url when available "public_url": url } return JsonResponse(response, status=200)