workbench snapshot api: return dhid and public url #11
18
api/views.py
18
api/views.py
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
|
@ -22,6 +23,7 @@ from user.models import User
|
|||
from api.models import Token
|
||||
from api.tables import TokensTable
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def save_in_disk(data, user):
|
||||
pass
|
||||
|
@ -65,13 +67,23 @@ def NewSnapshot(request):
|
|||
# save_in_disk(data, tk.user)
|
||||
|
||||
try:
|
||||
Build(data, tk.owner)
|
||||
except Exception:
|
||||
snapshot_build = Build(data, tk.owner)
|
||||
# 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': 'success'}, status=200)
|
||||
|
||||
|
||||
return JsonResponse(response, status=200)
|
||||
|
||||
|
||||
class TokenView(DashboardView, SingleTableView):
|
||||
|
|
Loading…
Reference in a new issue