(upload_file)
convert django FILES object to the filename of a tempfile
    that gets deleted when you leave the with...as block

    usage:
        with _excel_upload_file(upload_file) as filename:
            # you can now access the file by filename
            upload_fixture_file(domain, filename, replace)
            ...
convert django FILES object to the filename of a tempfile
    that gets deleted when you leave the with...as block
convert django FILES object to the filename of a tempfile that gets deleted when you leave the with ... as block
def _excel_upload_file(upload_file):
    """
    convert django FILES object to the filename of a tempfile
    that gets deleted when you leave the with...as block

    usage:
        with _excel_upload_file(upload_file) as filename:
            # you can now access the file by filename
            upload_fixture_file(domain, filename, replace)
            ...

    """
    with NamedTemporaryFile(suffix='.xlsx') as tempfile:
        # copy upload_file into tempfile (flush guarantees the operation is completed)
        for chunk in upload_file.chunks():
            tempfile.write(chunk)
        tempfile.flush()
        yield tempfile.name
def _excel_upload_file ( upload_file ) : with NamedTemporaryFile ( suffix = '.xlsx' ) as tempfile : # copy upload_file into tempfile (flush guarantees the operation is completed) for chunk in upload_file . chunks ( ) : tempfile . write ( chunk ) tempfile . flush ( ) yield tempfile . name