Skip to content
Snippets Groups Projects

DOC: enhance sss documentation

Merged Henrik tom Wörden requested to merge f-sss-doc into dev
3 files
+ 46
0
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -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()
Loading