workbench snapshot api: return dhid and public url #11

Closed
pedro wants to merge 1 commit from api-snapshot_reponse-to-workbench into main

View file

@ -1,3 +1,4 @@
import logging
import json import json
from django.urls import reverse_lazy from django.urls import reverse_lazy
@ -22,6 +23,7 @@ from user.models import User
from api.models import Token from api.models import Token
from api.tables import TokensTable from api.tables import TokensTable
logger = logging.getLogger(__name__)
def save_in_disk(data, user): def save_in_disk(data, user):
pass pass
@ -65,13 +67,23 @@ def NewSnapshot(request):
# save_in_disk(data, tk.user) # save_in_disk(data, tk.user)
try: try:
Build(data, tk.owner) snapshot_build = Build(data, tk.owner)
except Exception: # TODO this is hardcoded, it should select the user preferred algorithm
dhid = snapshot_build.get_hid_14()
shortid = dhid[:6]
device_url = request.build_absolute_uri("/device")
response = {
'status': 'success',
'public_url': f"{device_url}/{dhid}",
'dhid': shortid,
}
except Exception as e:
logger.error(e)
return JsonResponse({'status': 'fail'}, status=200) return JsonResponse({'status': 'fail'}, status=200)
return JsonResponse({'status': 'success'}, status=200)
return JsonResponse(response, status=200)
class TokenView(DashboardView, SingleTableView): class TokenView(DashboardView, SingleTableView):