diff --git a/README_SETUP.md b/README_SETUP.md index e3b6e3bc3e8a69c2ff1e162476819ec76b93dbe9..567a24663d5c1c7a3343e3e0f137b8196831c7bd 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 0000000000000000000000000000000000000000..d60cf6116e6e2a19e5422eb86979c96d54652869 --- /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 6dc08999f38e1912e72440c609b8cde1ea7ce0bb..95a0bac0f3911cfee1d6ca626c2cf9707d916470 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() + +