Пример #1
0
def pt_job_id_json(request, api_ver, project_id, job_id):

    if request.method == 'PATCH':
        try:
            data = json.loads(request.body.decode("utf-8"))
        except json.JSONDecodeError:
            return HttpResponseBadRequest("Wrong json")

        try:
            job_id = data['job_id']
            link = data['link']
        except KeyError:
            return HttpResponseBadRequest("Wrong data in json")

        try:
            JobModel.pt_change_regression_link(job_id, link)
        except JobModel.DoesNotExist:
            HttpResponseBadRequest("There is no such job")
        except KeyError:
            return HttpResponseBadRequest(
                "Job has already been in this status")

        return HttpResponse("OK")

    elif request.method in ['PUT', 'GET', 'DELETE']:
        try:
            job = JobModel.objects.get(pk=job_id)
        except JobModel.DoesNotExist:
            return JsonResponse([], safe=False, status=http.client.NOT_FOUND)

        if request.method == 'PUT':
            if request.content_type != "application/json":
                return HttpResponseBadRequest(
                    "content_type must be 'application/json'")

            body_unicode = request.body.decode('utf-8')
            try:
                body = json.loads(body_unicode)
            except ValueError as ve:
                return HttpResponseBadRequest(
                    "unable to parse JSON data. Error : {0}".format(ve))

            job.pt_update(body)
            messages.success(request,
                             "job #%s was successfully edited" % str(job_id))
            return HttpResponse("OK")

        elif request.method == 'GET':
            return JsonResponse(JobNestedSerializer(job).data, safe=False)

        elif request.method == 'DELETE':
            job.deleted = True
            job.save()
            messages.success(request, "job #%s was deleted" % str(job_id))
            return JsonResponse([], safe=False)

    return JsonResponse([], safe=False, status=http.client.NOT_IMPLEMENTED)
Пример #2
0
def pt_job_id_json(request, api_ver, project_id, job_id):

    if request.method == 'PATCH':
        try:
            data = json.loads(request.body.decode("utf-8"))
        except json.JSONDecodeError:
            return HttpResponseBadRequest("Wrong json")

        try:
            job_id = data['job_id']
            link = data['link']
        except KeyError:
            return HttpResponseBadRequest("Wrong data in json")

        try:
            JobModel.pt_change_regression_link(job_id, link)
        except JobModel.DoesNotExist:
            HttpResponseBadRequest("There is no such job")
        except KeyError:
            return HttpResponseBadRequest(
                "Job has already been in this status")

        return HttpResponse("OK")

    if request.method == 'GET' or request.method == 'DELETE':
        try:
            job = JobModel.objects.get(pk=job_id)
        except JobModel.DoesNotExist:
            return JsonResponse([], safe=False, status=http.client.NOT_FOUND)

        if request.method == 'GET':
            return JsonResponse(JobNestedSerializer(job).data, safe=False)
        else:
            job.deleted = True
            job.save()
            messages.success(request, "job #%s was deleted" % str(job_id))
            return JsonResponse([], safe=False)

    return JsonResponse([], safe=False, status=http.client.NOT_IMPLEMENTED)