Ejemplo n.º 1
0
def project_audit_parameter_list(request, project_uuid):
    project = Project.objects.get(uuid=project_uuid)
    check_if_admin_of_project(request.user.id, project.uuid)
    data = JSONParser().parse(request)
    serializer = ProjectAuditParametersSerializer(data=data)
    if serializer.is_valid():
        audit_parameter = ProjectAuditParameters.objects.create(
            project=project, **serializer.validated_data)
        audit_parameter.save()
        serializer = ProjectAuditParametersSerializer(audit_parameter)
        return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)
    return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
def project_audit_parameters_detail(request, project_uuid, audit_parameters_uuid):
    project = get_object_or_404(Project, pk=project_uuid)
    audit_parameters = get_object_or_404(
        ProjectAuditParameters, pk=audit_parameters_uuid
    )
    check_if_member_of_project(request.user.id, project.uuid)

    if audit_parameters.project != project:
        return JsonResponse({}, status=status.HTTP_400_BAD_REQUEST)

    if request.method == "GET":
        serializer = ProjectAuditParametersSerializer(audit_parameters)
        return JsonResponse(serializer.data)

    elif request.method == "PUT":
        check_if_admin_of_project(request.user.id, project.uuid)
        data = JSONParser().parse(request)
        serializer = ProjectAuditParametersSerializer(audit_parameters, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == "DELETE":
        check_if_admin_of_project(request.user.id, project.uuid)
        audit_parameters.delete()
        return JsonResponse({}, status=status.HTTP_204_NO_CONTENT)