(request)
return Response(serialize.data, status=response_status.HTTP_200_OK)
Creates a sample input. Only image input is supported currently.

    The data passed into the POST request needs to contain:
        demo_id (str): The demo that the sample input should belong to.
        sample-image-* (file): A value with its key having 'sample-image'
            as a prefix, containing the image file.
Creates a sample input. Only image input is supported currently.
Creates a sample input . Only image input is supported currently .
def upload_sample_input(request):
    """
    Creates a sample input. Only image input is supported currently.

    The data passed into the POST request needs to contain:
        demo_id (str): The demo that the sample input should belong to.
        sample-image-* (file): A value with its key having 'sample-image'
            as a prefix, containing the image file.
    """
    data = request.data
    demo_id = data["demo_id"]
    demo = Demo.objects.get(id=demo_id)
    for key, value in data.items():
        if key.startswith("sample-image"):
            img = request.FILES[key]
            absolute_path = default_storage.save(settings.MEDIA_ROOT, ContentFile(img.read()))
            relative_path = '/media/' + absolute_path.split('media/')[-1]
            sample_input = SampleInput.objects.create(demo=demo, type_of_input=3, value=relative_path)
            serialize = SampleInputSerializer(sample_input)
            if ("test" in sys.argv):
                os.remove(absolute_path)
    sample_inputs = SampleInput.objects.filter(demo=demo)
    serialize = SampleInputSerializer(sample_inputs, many=True)
    return Response(serialize.data, status=response_status.HTTP_200_OK)
def upload_sample_input ( request ) : data = request . data demo_id = data [ "demo_id" ] demo = Demo . objects . get ( id = demo_id ) for key , value in data . items ( ) : if key . startswith ( "sample-image" ) : img = request . FILES [ key ] absolute_path = default_storage . save ( settings . MEDIA_ROOT , ContentFile ( img . read ( ) ) ) relative_path = '/media/' + absolute_path . split ( 'media/' ) [ - 1 ] sample_input = SampleInput . objects . create ( demo = demo , type_of_input = 3 , value = relative_path ) serialize = SampleInputSerializer ( sample_input ) if ( "test" in sys . argv ) : os . remove ( absolute_path ) sample_inputs = SampleInput . objects . filter ( demo = demo ) serialize = SampleInputSerializer ( sample_inputs , many = True ) return Response ( serialize . data , status = response_status . HTTP_200_OK )