From 0e05c049147c6be8c49d17e51c50440d00c28003 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Thu, 1 Feb 2024 15:42:31 +0300 Subject: Integrate CKEditor into metadata editing. * gn2/wqflask/__init__.py: Register blueprint endpoint for metadata edits. * gn2/wqflask/edit.py (metadata_edit): New function. (save): Ditto. * gn2/wqflask/templates/metadata/dataset.html: New template. * gn2/wqflask/templates/metadata/editor.html: New template. Signed-off-by: Munyoki Kilyungi --- gn2/wqflask/__init__.py | 3 ++ gn2/wqflask/edit.py | 48 ++++++++++++++++++ gn2/wqflask/templates/metadata/dataset.html | 12 ++++- gn2/wqflask/templates/metadata/editor.html | 77 +++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 gn2/wqflask/edit.py create mode 100644 gn2/wqflask/templates/metadata/editor.html (limited to 'gn2/wqflask') diff --git a/gn2/wqflask/__init__.py b/gn2/wqflask/__init__.py index 8e96228d..325a1cef 100644 --- a/gn2/wqflask/__init__.py +++ b/gn2/wqflask/__init__.py @@ -21,6 +21,7 @@ from gn3.authentication import DataRole, AdminRole from gn2.wqflask.group_manager import group_management from gn2.wqflask.resource_manager import resource_management from gn2.wqflask.metadata_edits import metadata_edit +from gn2.wqflask.edit import metadata from gn2.wqflask.api.markdown import glossary_blueprint from gn2.wqflask.api.markdown import references_blueprint @@ -89,6 +90,8 @@ app.register_blueprint(jupyter_notebooks, url_prefix="/jupyter_notebooks") app.register_blueprint(resource_management, url_prefix="/resource-management") app.register_blueprint(metadata_edit, url_prefix="/datasets/") +app.register_blueprint(metadata, + url_prefix="/metadata/") app.register_blueprint(group_management, url_prefix="/group-management") app.register_blueprint(jobs_bp, url_prefix="/jobs") app.register_blueprint(oauth2, url_prefix="/oauth2") diff --git a/gn2/wqflask/edit.py b/gn2/wqflask/edit.py new file mode 100644 index 00000000..8d176608 --- /dev/null +++ b/gn2/wqflask/edit.py @@ -0,0 +1,48 @@ +import requests + +from pathlib import Path + +from flask import (Blueprint, + redirect, + render_template, + request) + +from gn2.wqflask.decorators import login_required +from gn2.utility.tools import GN3_LOCAL_URL + + +metadata = Blueprint("metadata", __name__) + + +@metadata.route("/edit") +@login_required(pagename="Dataset Metadata Editing") +def metadata_edit(): + match request.args.get("type"): + case "dcat:Dataset": + metadata = requests.get( + Path( + GN3_LOCAL_URL, + "metadata/datasets/", + (_name := request.args.get("name")) + ).as_posix() + ).json() + __section = request.args.get("section") + return render_template( + "metadata/editor.html", + name=_name, + metadata=metadata, + section=__section, + edit=metadata.get(__section), + ) + + +@metadata.route("/save", methods=["POST"]) +@login_required(pagename="Dataset Metadata Editing") +def save(): + __content = request.form.get("editor") + __summary = request.form.get("summary") + __type = request.form.get("type") + match __type: + case "dcat:Dataset": + # XXX: TODO: Method for saving data + return redirect(f"/datasets/{request.form.get('label')}") diff --git a/gn2/wqflask/templates/metadata/dataset.html b/gn2/wqflask/templates/metadata/dataset.html index 23ceb3b5..1946d01a 100644 --- a/gn2/wqflask/templates/metadata/dataset.html +++ b/gn2/wqflask/templates/metadata/dataset.html @@ -93,9 +93,17 @@ -
+