Base
DataBlock
¶
Base class for a data block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_id
|
str | None
|
The item to which the block is attached. |
None
|
init_data
|
dict | None
|
A dictionary of data to initialise the block with. |
None
|
unique_id
|
str | None
|
A unique id for the block, used in the DOM and database. |
None
|
accepted_file_extensions
¶
A list of file extensions that the block will attempt to read.
data
¶
data = {'item_id': item_id, 'blocktype': self.blocktype, 'block_id': self.block_id, None: self.defaults}
defaults
¶
Any default values that should be set if they are not supplied during block init.
description
¶
description: str = 'Generic Block'
A longer description outlining the purpose and capability of the block.
name
¶
name: str = 'base'
The human-readable block name specifying which technique or file format it pertains to.
plot_functions
¶
A list of methods that will generate plots for this block.
events_by_name
¶
Returns a dict of registered events for this block.
from_web
¶
Initialise the block state from data passed via web request with a given item and block ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The block data to initialiaze the block with. |
required |
stored_data
|
dict | None
|
The stored database state of the block, if any, used to preserve server-authoritative fields that cannot be set from the web. |
None
|
null_event
¶
null_event(**kwargs)
A null debug event that does nothing but logs its kwargs and overwrites the data dict with the args.
process_events
¶
Handle any supported events passed to the block.
to_db
¶
to_db() -> dict
returns a dictionary with the data for this block, ready to be input into mongodb
to_web
¶
Returns a JSON serializable dictionary to render the data block on the web.
update_from_web
¶
Update the block with validated data received from a web request. Will strip any fields that are "computed" or otherwise not controllable by the user, restoring their stored database values where available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary of data to update the block with. |
required |
stored_data
|
dict | None
|
The stored database state of the block, if any. |
None
|
classproperty
¶
classproperty(method=None)
event
¶
Decorator to register an event with a block.
generate_js_callback_single_float_parameter
¶
generate_js_callback_single_float_parameter(event_name: str, parameter: str, block_id: str, throttled: bool = False) -> str
Generates a Bokeh JS callback that can be attached to a widget and used to trigger datalab block events with a single named parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
The name of the block method to call. |
required |
parameter
|
str
|
The name of the parameter to update. |
required |
block_id
|
str
|
The ID of the block to target for the event. |
required |
throttled
|
bool
|
Whether to bind to the widget's |
False
|
generate_random_id
¶
generate_random_id()
This function generates a random 15-length string for use as an id for a datablock. It should be sufficiently random that there is a negligible risk of ever generating the same id twice, so this is a unique id that can be used as a unique database refrence and also can be used as id in the DOM. Note: uuid.uuid4() would do this too, but I think the generated ids are too long and ugly.
The ids here are HTML id friendly, using lowercase letters and numbers. The first character is always a letter.