Jobs Table¶
Last Updated: July 2022
- class tethys_sdk.gizmos.JobsTable(jobs, column_fields, show_status=True, show_actions=True, monitor_url='', results_url='', hover=False, striped=False, bordered=False, condensed=False, attributes=None, classes='', refresh_interval=5000, delay_loading_status=True, show_detailed_status=False, actions=None, enable_data_table=False, data_table_options=None)¶
A jobs table can be used to display users' jobs. The JobsTable gizmo takes the same formatting options as the table view gizmo, but does not allow the columns to be edited. Additional attributes for the jobs table allows for a dynamically updating status field, and action buttons.
- jobs¶
A list/tuple of TethysJob objects.
- Type
tuple or list, required
- column_fields¶
A tuple or list of strings that represent TethysJob object attributes to show in the columns.
- Type
tuple or list, required
- show_status¶
Add a column to the table to show dynamically updating job status. Default is True.
- Type
bool
- show_actions¶
Add a column to the table to show a dynamically updating dropdown list of actions that can be done on the job. The available actions are determined by actions option. Actions are enabled/disabled based on the job status. If this is False then then actions option ignored.
- Type
bool
- actions¶
A list of default actions or custom action arguments that can be done on a job with the | character used to divide the actions into sections. If None then all the default actions will be used (i.e. ['run', 'resubmit', '|', 'logs', 'monitor', 'results', '|', 'terminate', 'delete']). Note that if monitor_url and results_url are supplied then 'monitor' and 'results' respectively will be added if not already in the list. If they are not provided then monitor and results will be removed from the list if present. Default is None.
- Type
list
- monitor_url¶
A string representing the namespaced path to a controller to that displays monitoring information about a running job (e.g. app_name:monitoring_controller)
- Type
str
- results_url¶
A string representing the namespaced path to a controller to that displays job results (e.g. app_name:results_controller)
- Type
str
- hover¶
Illuminate rows on hover (does not work on striped tables)
- Type
bool
- striped¶
Stripe rows
- Type
bool
- bordered¶
Add borders and rounded corners
- Type
bool
- condensed¶
A more tightly packed table
- Type
bool
- attributes¶
A dictionary representing additional HTML attributes to add to the primary element (e.g. {"onclick": "run_me();"}).
- Type
dict
- classes¶
Additional classes to add to the primary HTML element (e.g. "example-class another-class").
- Type
str
- refresh_interval¶
The refresh interval for the runtime and status fields in milliseconds. Default is 5000.
- Type
int
- show_detailed_status¶
Show status of each node in CondorWorkflow jobs when True. Defaults to False.
- Type
bool
Controller Example
from tethys_sdk.gizmos import JobsTable jobs_table_options = JobsTable( jobs=jobs, column_fields=('id', 'name', 'description', 'creation_time', 'execute_time'), actions=['run', 'resubmit', '|', 'logs', '|', 'terminate', 'delete'], hover=True, striped=False, bordered=False, condensed=False, results_url='app_name:results_controller', ) context = { 'jobs_table_options': jobs_table_options, }
Controller Example with Custom Actions
from tethys_sdk.gizmos import JobsTable, CustomJobAction def custom_action(job): # do something with job def custom_action2(job): # do something with job def enable_custom_action(job): # custom logic to determine if action should be enabled def controller(request): ... jobs_table_options = JobsTable( jobs=jobs, column_fields=('id', 'name', 'description', 'creation_time', 'execute_time'), actions=[ 'run', 'resubmit', '|', 'logs', '|', 'terminate', 'delete', '|', CustomJobAction( label='Custom Action', callback_or_url=custom_action, enabled_callback=enable_custom_action, confirmation_message='Do you really want to do this?', show_overlay=True, # displays the overlay loading spinner until the custom action function returns ), # Custom actions can also be defined as a list/tuple of args. The only required arguments are label and callback_or_url ('Another Custom Action', custom_action2), # Instead of a function a custom action can just be a url name for a custom endpoint ('Yet Another Custom Action', 'my_app:custom_endpoint'), # An alternative type of custom action is to provide an endpoint to get content for a modal CustomJobAction('Custom Modal Content', modal_url='my_app:get_modal_content'), ], hover=True, striped=False, bordered=False, condensed=False, results_url='app_name:results_controller', ) context = { 'jobs_table_options': jobs_table_options, } ...
Template Example
{% load tethys_gizmos %} {% gizmo jobs_table_options %}
Tip
To see the Jobs Table Gizmo in action, install the Gizmo Showcase Tethys app.
- class tethys_sdk.gizmos.CustomJobAction(label, callback_or_url=None, enabled_callback=None, confirmation_message=None, show_overlay=False, modal_url=None, job_type=None)¶
A
CustomJobAction
is used to create custom actions in the actions dropdown menu of the jobs table.- label¶
The display name of the action that will show in the actions dropdown.
- Type
str, required
- callback_or_url¶
The name on a callable attribute on the
job_type
object or a callable that accepts aTethysJob
as an argument. Or it can be the name of a URL that the custom action option will link to.- Type
str or callable, required if
modal_url
is not supplied
- enabled_callback¶
A callable that accepts a
job_type
object as an argument and returns True if the action should be enabled or False if it should be disabled.- Type
callable
- confirmation_message¶
A message to display in a modal to ask for confirmation to perform the action.
- Type
str
- show_overlay¶
Whether to show an overlay with a loading spinner while the action is being called.
- Type
bool
- modal_url¶
The name of a URL to retrieve content to populate a modal.
- Type
str, required if
callback_or_url
is not supplied
- job_type¶
A subclass of
TethysJob
. Must be specified if thecallback_or_url
argument is an attribute that is only defined at the subclass level.- Type
class
Examples:
def custom_action(job): # do something with job def custom_action2(job): # do something with job def enable_custom_action(job): # custom logic to determine if action should be enabled CustomJobAction( label='Custom Action', callback_or_url=custom_action, enabled_callback=enable_custom_action, confirmation_message='Do you really want to do this?', show_overlay=True, # displays the overlay loading spinner until the custom action function returns )
Tip
For a complete example of using
CustomJobAction
refer to the Gizmo Showcase Tethys app code.