示例#1
0
def delete_file(request, id, name):
    fs = FileSystemStorage()
    if not experiment.file_exists(id, name):
        return render(request, '404.html')

    try:
        fs.delete('experiments/' + id + '/' + name)
    except:
        return render(
            request, 'nix/experiment.html', {
                'experiment_id': id,
                'error_message': "The file was not deleted.",
                'transformed_files': experiment.get_json_ld_files(id),
                'nix_transformed':
                experiment.get_nix_transformed_bool_list(id),
                'files': experiment.get_nix_files(id)
            })

    return render(
        request, 'nix/experiment.html', {
            'experiment_id': id,
            'success_message': "The file was deleted.",
            'transformed_files': experiment.get_json_ld_files(id),
            'nix_transformed': experiment.get_nix_transformed_bool_list(id),
            'files': experiment.get_nix_files(id)
        })
示例#2
0
def upload_files(request, id):
    if not experiment.experiment_exists(id):
        return render(request, '404.html')

    if request.FILES.getlist('upload_files', False):
        files = request.FILES.getlist('upload_files')

        # checks file extensions
        if not experiment.check_file_extensions(files):
            return render(
                request, 'nix/experiment.html', {
                    'experiment_id': id,
                    'error_message':
                    "The file can only have a .nix or .h5 extension.",
                    'transformed_files': experiment.get_json_ld_files(id),
                    'nix_transformed':
                    experiment.get_nix_transformed_bool_list(id),
                    'files': experiment.get_nix_files(id)
                })

        # checks unique file names
        if not experiment.check_files_names_experiment(files, id):
            return render(
                request, 'nix/experiment.html', {
                    'experiment_id': id,
                    'error_message': "Files do not contain unique names.",
                    'transformed_files': experiment.get_json_ld_files(id),
                    'nix_transformed':
                    experiment.get_nix_transformed_bool_list(id),
                    'files': experiment.get_nix_files(id)
                })

        experiment.save_files(files, id)
        return render(
            request, 'nix/experiment.html', {
                'experiment_id': id,
                'success_message': "File upload successful.",
                'transformed_files': experiment.get_json_ld_files(id),
                'nix_transformed':
                experiment.get_nix_transformed_bool_list(id),
                'files': experiment.get_nix_files(id)
            })
    return render(
        request, 'nix/experiment.html', {
            'experiment_id': id,
            'error_message': "No file selected.",
            'transformed_files': experiment.get_json_ld_files(id),
            'nix_transformed': experiment.get_nix_transformed_bool_list(id),
            'files': experiment.get_nix_files(id)
        })
示例#3
0
def show_experiment_page(request, id):
    if not experiment.experiment_exists(id):
        return render(request, '404.html')

    return render(
        request, 'nix/experiment.html', {
            'experiment_id': id,
            'transformed_files': experiment.get_json_ld_files(id),
            'nix_transformed': experiment.get_nix_transformed_bool_list(id),
            'files': experiment.get_nix_files(id)
        })
示例#4
0
def convert_all(request, id):
    error_message = ""
    success_message = "All files have been converted."
    if not experiment.experiment_exists(id):
        return render(request, '404.html')

    files = experiment.get_nix_files(id)

    for i in range(len(files)):
        if not experiment.convert_metadata(id, files[i]):
            success_message = ""
            error_message = "An error occurred while converting the file named " + files[
                i] + "."
            break

    return render(
        request, 'nix/experiment.html', {
            'experiment_id': id,
            'error_message': error_message,
            'success_message': success_message,
            'transformed_files': experiment.get_json_ld_files(id),
            'nix_transformed': experiment.get_nix_transformed_bool_list(id),
            'files': experiment.get_nix_files(id)
        })
示例#5
0
def convert_file(request, id, name):
    error_message = ""
    success_message = "The requested experiment has been converted."
    if not experiment.file_exists(id, name):
        return render(request, '404.html')

    if not experiment.convert_metadata(id, name):
        error_message = "An error occurred while converting the file."
        success_message = ""

    return render(
        request, 'nix/experiment.html', {
            'experiment_id': id,
            'error_message': error_message,
            'success_message': success_message,
            'transformed_files': experiment.get_json_ld_files(id),
            'nix_transformed': experiment.get_nix_transformed_bool_list(id),
            'files': experiment.get_nix_files(id)
        })