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) })
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) })
def process_query(request, id): error_message = "" query_result = "" file_name = request.POST.get("transformed_file", "") if file_name == "" or not experiment.file_exists(id, file_name): return render(request, '404.html') query = request.POST.get("query", "") module_dir = os.path.dirname(__file__) # get current directory file_path = os.path.join(module_dir, '../media/experiments/' + id + '/' + file_name) g = Graph() try: result = g.parse(file_path, format="json-ld") except: error_message = "Invalid JSON-LD file." try: query_result = g.query(query) except: error_message = "An error occurred while executing the query." return render( request, 'nix/find.html', { 'error_message': error_message, 'query': query, 'experiment_id': id, 'query_result': query_result, 'transformed_files': experiment.get_json_ld_files(id), 'selected_file': file_name })
def show_find_page(request, id): if not experiment.experiment_exists(id): return render(request, '404.html') return render(request, 'nix/find.html', { 'experiment_id': id, 'transformed_files': experiment.get_json_ld_files(id) })
def show_metadata_page(request, id): if not experiment.experiment_exists(id): return render(request, '404.html') return render(request, 'nix/metadata.html', { 'transformed_files': experiment.get_json_ld_files(id), 'experiment_id': id })
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) })
def show_metadata(request, id): file_name = request.POST.get("transformed_file", "") if file_name == "" or not experiment.file_exists(id, file_name): return render(request, '404.html') file_content = unicode(experiment.read_file(id, file_name), "utf-8") return render( request, 'nix/metadata.html', { 'experiment_id': id, 'transformed_files': experiment.get_json_ld_files(id), 'selected_file': file_name, 'file_content': file_content })
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) })
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) })