Compare commits

..

2 commits

Author SHA1 Message Date
pedro 57cec14429 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}
2024-10-15 13:11:24 +02:00
pedro 5e6546169b 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}
2024-10-15 13:09:34 +02:00

View file

@ -1,6 +1,5 @@
import json import json
from django.conf import settings
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -82,15 +81,14 @@ def NewSnapshot(request):
if not annotation: if not annotation:
return JsonResponse({'status': 'fail'}, status=200) return JsonResponse({'status': 'fail'}, status=200)
url = "{}://{}{}".format( url_args = reverse_lazy("device:details", args=(annotation.value,))
request.scheme, url = request.build_absolute_uri(url_args)
settings.DOMAIN,
reverse_lazy("device:details", args=(annotation.value,))
)
response = { response = {
"status": "success", "status": "success",
"dhid": annotation.value[:6].upper(), "dhid": annotation.value[:6].upper(),
"url": url, "url": url,
# TODO replace with public_url when available
"public_url": url "public_url": url
} }
return JsonResponse(response, status=200) return JsonResponse(response, status=200)