def handle_reupload(dt_node_id=None, saved_filename=None, document=None, eml_node=None, uploads_folder=None, name_chg_ok=False, delimiter=None, quote_char=None):
    dataset_node = eml_node.find_child(names.DATASET)
    if (not dataset_node):
        dataset_node = new_child_node(names.DATASET, eml_node)
    if (not saved_filename):
        raise MissingFileError('Unexpected error: file not found')
    dt_node = Node.get_node_instance(dt_node_id)
    num_header_rows = 1
    filepath = os.path.join(uploads_folder, saved_filename)
    if (not name_chg_ok):
        if column_names_changed(filepath, delimiter, quote_char, dt_node):
            return redirect(url_for(PAGE_REUPLOAD_WITH_COL_NAMES_CHANGED, saved_filename=saved_filename, dt_node_id=dt_node_id), code=307)
    try:
        (new_dt_node, new_column_vartypes, new_column_names, new_column_categorical_codes, *_) = load_data_table(uploads_folder, saved_filename, num_header_rows, delimiter, quote_char)
        types_changed = None
        try:
            check_data_table_similarity(dt_node, new_dt_node, new_column_vartypes, new_column_names, new_column_categorical_codes)
        except ValueError as err:
            types_changed = err.args[0]
        except FileNotFoundError as err:
            error = err.args[0]
            flash(error, 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
        except IndexError as err:
            error = err.args[0]
            flash(f'Re-upload not done. {error}', 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
        try:
            update_data_table(dt_node, new_dt_node, new_column_names, new_column_categorical_codes)
            os.rename(filepath, filepath.replace('.ezeml_tmp', ''))
            if types_changed:
                err_string = 'Please note: One or more columns in the new table have a different data type than they had in the old table.<ul>'
                for (col_name, old_type, new_type, attr_node) in types_changed:
                    dt.change_measurement_scale(attr_node, old_type.name, new_type.name)
                    err_string += f'<li><b>{col_name}</b> changed from {old_type.name} to {new_type.name}'
                err_string += '</ul>'
                flash(Markup(err_string))
        except Exception as err:
            error = err.args[0]
            flash(f'Data table could not be re-uploaded. {error}', 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
    except UnicodeDecodeError as err:
        errors = display_decode_error_lines(filepath)
        return render_template('encoding_error.html', filename=document, errors=errors)
    except DataTableError as err:
        flash(f'Data table has an error: {err.message}', 'error')
        return redirect(request.url)
    data_file = saved_filename.replace('.ezeml_tmp', '')
    flash(f'Loaded {data_file}')
    dt_node.parent = dataset_node
    object_name_node = dt_node.find_descendant(names.OBJECTNAME)
    if object_name_node:
        object_name_node.content = data_file
    user_data.add_data_table_upload_filename(data_file)
    if new_column_vartypes:
        user_data.add_uploaded_table_properties(data_file, new_column_vartypes, new_column_names, new_column_categorical_codes)
    delete_data_files(uploads_folder)
    backup_metadata(filename=document)
    save_both_formats(filename=document, eml_node=eml_node)
    return redirect(url_for(PAGE_DATA_TABLE, filename=document, dt_node_id=dt_node.id, delimiter=delimiter, quote_char=quote_char))
def handle_reupload(dt_node_id=None, saved_filename=None, document=None, eml_node=None, uploads_folder=None, name_chg_ok=False, delimiter=None, quote_char=None):
    dataset_node = eml_node.find_child(names.DATASET)
    if (not dataset_node):
        dataset_node = new_child_node(names.DATASET, eml_node)
    if (not saved_filename):
        raise MissingFileError('Unexpected error: file not found')
    dt_node = Node.get_node_instance(dt_node_id)
    num_header_rows = 1
    filepath = os.path.join(uploads_folder, saved_filename)
    if (not name_chg_ok):
        if column_names_changed(filepath, delimiter, quote_char, dt_node):
            return redirect(url_for(PAGE_REUPLOAD_WITH_COL_NAMES_CHANGED, saved_filename=saved_filename, dt_node_id=dt_node_id), code=307)
    try:
        (new_dt_node, new_column_vartypes, new_column_names, new_column_categorical_codes, *_) = load_data_table(uploads_folder, saved_filename, num_header_rows, delimiter, quote_char)
        types_changed = None
        try:
            check_data_table_similarity(dt_node, new_dt_node, new_column_vartypes, new_column_names, new_column_categorical_codes)
        except ValueError as err:
            types_changed = err.args[0]
        except FileNotFoundError as err:
            error = err.args[0]
            flash(error, 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
        except IndexError as err:
            error = err.args[0]
            flash(f'Re-upload not done. {error}', 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
        try:
            update_data_table(dt_node, new_dt_node, new_column_names, new_column_categorical_codes)
            os.rename(filepath, filepath.replace('.ezeml_tmp', ))
            if types_changed:
                err_string = 'Please note: One or more columns in the new table have a different data type than they had in the old table.<ul>'
                for (col_name, old_type, new_type, attr_node) in types_changed:
                    dt.change_measurement_scale(attr_node, old_type.name, new_type.name)
                    err_string += f'<li><b>{col_name}</b> changed from {old_type.name} to {new_type.name}'
                err_string += '</ul>'
                flash(Markup(err_string))
        except Exception as err:
            error = err.args[0]
            flash(f'Data table could not be re-uploaded. {error}', 'error')
            return redirect(url_for(PAGE_DATA_TABLE_SELECT, filename=document))
    except UnicodeDecodeError as err:
        errors = display_decode_error_lines(filepath)
        return render_template('encoding_error.html', filename=document, errors=errors)
    except DataTableError as err:
        flash(f'Data table has an error: {err.message}', 'error')
        return redirect(request.url)
    data_file = saved_filename.replace('.ezeml_tmp', )
    flash(f'Loaded {data_file}')
    dt_node.parent = dataset_node
    object_name_node = dt_node.find_descendant(names.OBJECTNAME)
    if object_name_node:
        object_name_node.content = data_file
    user_data.add_data_table_upload_filename(data_file)
    if new_column_vartypes:
        user_data.add_uploaded_table_properties(data_file, new_column_vartypes, new_column_names, new_column_categorical_codes)
    delete_data_files(uploads_folder)
    backup_metadata(filename=document)
    save_both_formats(filename=document, eml_node=eml_node)
    return redirect(url_for(PAGE_DATA_TABLE, filename=document, dt_node_id=dt_node.id, delimiter=delimiter, quote_char=quote_char))