Python

HTML Rendering Commands

There are three ways to update the html fields during the rendering process.

The return value from the function called should be a dictionary.

Update a field:

{"<field_name>": {"action": "update", "value": <value>}}

Delete a field:

{"<field_name>": {"action": "delete"}}

Ignore a field:

{"<field_name>": {"action": "ignore"}}

The default action is to ignore.

Example

Form Design

Screenshot

Form Rendered

Screenshot

Calling User Defined Functions

Functions defined in other designs can also be called using the subtask function.

Car should be taken when calling other functions as this is a much slower process compared with defining the function locally and should therefore be used sparingly.

Subtask is a function with the following docstring:

def subtask(design_name, commit_number, function_name, function_args, function_kwargs):
    """
    Args:
        design_name (str): The name of the design to call.
        commit_number (int): The version of the design to call.
        function_name (str): The name of the function to call.
        function_args (tuple): A tuple of the arguments to pass to the function.
        function_kwargs (dict): A dictionary of key-word-arguments to pass to the function.
    """

Exception Handling

Form validation can be achieved by raising an Exception of type 'Warning', for example:

def main(form_data):
    number = form_data["a_number"]

    try:
        number = float(number)
    except ValueError:
        raise Warning("Enter a number between 1 and 10")

Upon rendering the message will be automatically displayed to the user at the top of the page, as in:

Screenshot

Imports

A number of libraries are available for importing include:

  • numpy
  • matplotlib
  • pandas