Commit 10cea177 authored by sebastien letort's avatar sebastien letort
Browse files

the job_response function breaks the API legacy.

It could though be used in a future V2.
Note that I used get_state_display in APIJobView instead of the local dictionnary.
parent ffa355b0
Pipeline #78090 passed with stages
in 3 minutes and 40 seconds
......@@ -5,6 +5,7 @@ import config.env
from django.core.validators import ValidationError
from django.http import JsonResponse
from django.shortcuts import redirect
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from main.helpers import upload_data, get_base_url, lookup_job_file, get_request_user
......@@ -21,29 +22,21 @@ def get_link(jobid, dir, filename, request):
return '/'.join((get_base_url(request), "datastore", str(jobid), filename))
def job_response(job, request):
status = {0: 'new',
1: 'waiting',
2: 'running',
3: 'done',
4: 'archived',
5: 'deleted',
6: 'aborting'}
job_dir = job.data_dir
files = {f: get_link(, job_dir, f, request) for f in os.listdir(job_dir)
if lookup_job_file(, f)}
return {str( {'status': status[job.state],
'files': files
class APIJobView(JobAuthMixin, View):
def get(self, request, pk):
job = Job.objects.get(id=pk)
return JsonResponse(job_response(job, request))
files = {}
for f in os.listdir(job.data_dir):
if lookup_job_file(, f):
files[f] = get_link(, job.data_dir, f, request)
response = { files,
"status": job.get_state_display().lower(),
return JsonResponse(response)
except Job.DoesNotExist as e:
log.error("Job not found %s", str(e))
return JsonResponse({'error': 'Job not found'}, status=404)
......@@ -90,7 +83,13 @@ def jobs(request):
job.state = Job.WAITING
return JsonResponse(job_response(job, request))
no_domain_url = reverse('api:job', kwargs={'pk'})
response = {
"avg_time": 0, # legacy, not relevant anymore
"id" :,
"url" : request.build_absolute_uri(no_domain_url),
return JsonResponse(response)
class APIDownloadView(JobAuthMixin, View):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment