From 3bd5af08632fac9b01eec92e875e34d956f3c0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Thu, 4 Jan 2024 13:41:38 +0100 Subject: [PATCH] DOC: enhance sss documentation --- README_SETUP.md | 1 + requirements-docs.txt | 4 ++ .../administration/server_side_scripting.rst | 41 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 requirements-docs.txt diff --git a/README_SETUP.md b/README_SETUP.md index e3b6e3bc..567a2466 100644 --- a/README_SETUP.md +++ b/README_SETUP.md @@ -241,6 +241,7 @@ Stand-alone documentation is built using Sphinx: `make doc` - recommonmark - sphinx - sphinx-rtd-theme +- sphinx-a4doc - sphinxcontrib-plantuml - javasphinx :: `pip3 install --user javasphinx` - Alternative, if javasphinx fails because python3-sphinx is too recent: diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 00000000..d60cf611 --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,4 @@ +sphinx-rtd-theme +sphinxcontrib-plantuml +javasphinx +sphinx-a4doc diff --git a/src/doc/administration/server_side_scripting.rst b/src/doc/administration/server_side_scripting.rst index 6dc08999..95a0bac0 100644 --- a/src/doc/administration/server_side_scripting.rst +++ b/src/doc/administration/server_side_scripting.rst @@ -83,3 +83,44 @@ An invocation via a button in javascript could look like: For more information see the :doc:`specification of the API <../specification/Server-side-scripting>` +Calling from the webui +--------------------- +Refer to `webui documentation <https://docs.indiscale.com//caosdb-webui/extension/forms.html#calling-a-server-side-script>`__ to learn how to setup the webui side of this interaction. + +The following example assumes that the form in the webui has only one filed +which is a file upload with the name ``csvfile``. + + +.. code-block:: python + + import os + import linkahead as db + from caosadvancedtools.serverside import helper + from caosadvancedtools.serverside.logging import configure_server_side_logging + + def main(): + parser = helper.get_argument_parser() + args = parser.parse_args() + db.configure_connection(auth_token=args.auth_token) + # setup logging and reporting if serverside execution + userlog_public, htmluserlog_public, debuglog_public = configure_server_side_logging() + + if not hasattr(args, "filename") or not args.filename: + raise RuntimeError("No file with form data provided!") + + # Read the input from the form (form.json) + with open(args.filename) as form_json: + form_data = json.load(form_json) + + # files are uploaded to this dicectory + upload_dir = os.path.dirname((args.filename)) + # Read content of th uplaoded file + csv_file_path = os.path.join(upload_dir, form_data["csvfile"]) + + # Do something with the upload csv file... + + + if __name__ == "__main__": + main() + + -- GitLab