pydent.models.Operation¶
-
class
pydent.models.
Operation
(operation_type_id=None, operation_type=None, status=None, x=0, y=0)[source]¶ Bases:
pydent.models.field_value_mixins.FieldValueInterface
,pydent.models.data_associations.DataAssociatorMixin
,pydent.base.ModelBase
A Operation model.
-
__init__
(operation_type_id=None, operation_type=None, status=None, x=0, y=0)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([operation_type_id, …])Initialize self.
add_data
(data)Initializes fake attributes that correspond to data.
add_to_input_array
(name[, sample, item, …])Creates and adds a new input
FieldValue
.add_to_output_array
(name[, sample, item, …])Creates and adds a new output
FieldValue
.Resets the primary key of the model and assigns a new rid.
append_to_many
(name, model)Appends a model to the many relationship.
associate
(key, value[, upload, create_new, save])Adds a data association with the key and value to this object.
associate_file
(key, value, file[, job_id])Associate a file.
associate_file_from_path
(key, value, filepath)Associate a file from a filepath.
connect_to_session
(session)Connect model to a session.
copy
([keep])Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g.
create_interface
()- rtype
Union
[QueryInterface
,BrowserInterface
]
dump
([only, include, ignore, …])Dump (serialize) the Aquarium model instance to JSON.
field_value
(name, role)Returns
FieldValue
with name and role.field_value_array
(name, role)Returns
FieldValue
array with name and role.find
(session, model_id)Finds a model instance by its model_id.
find_callback
(model_name, model_id)Finds a model using the model interface and model_id.
get
(key)get_data_associations
(key)get_deserialized
(name)Get deserialized data by name.
get_field_type
(name, role)Returns a
pydent.models.FieldType
by its name and role from the instance’s metaclass.get_field_types
([name, role])Returns a list of
pydent.models.FieldType
by their name and role from the instance’s metaclass.get_field_value
(name[, role])Returns a
pydent.models.FieldValue
by its name and role.get_field_value_array
(name[, role])Returns a list of
pydent.models.FieldValue
by their name and role.Returns the instance’s metatype.
get_relationships
()Returns the routing dictionary for this instance.
get_server_model_name
()get_tableized_name
()Initialize the
FieldValue
from theFieldType
of the parentOperation
type.input
(name)Returns the input
FieldValue
by name.input_array
(name)interface
(session)Creates a model interface from this class and a session.
is_deserialized
(name)Check if a given key has already been deserialized.
load
(*args, **kwargs)Deserialize the data to a model.
load_from
(data[, owner])Create a new model instance from loaded attributes.
new_field_value
(name[, role, values_dict])Instantiates a new
pydent.models.FieldValue
from a name and role.new_field_value_from_field_type
(field_type)Instantiates a new
pydent.models.FieldValue
from a.no_getter
(*_)Callback that always returns None.
one
(session, query, **kwargs)- rtype
one_callback
(model_name, *args, **kwargs)- rtype
output
(name)Returns the output
FieldValue
by name.output_array
(name)print
()refresh
()Refresh this model from data from the server.
reload
(data)Reload model attributes from new data.
reset_field
(name)Reset the field descriptor to its placeholder value, returning the behavior.
Safely returns the field value’s
pydent.models.FieldType
from the model.set_field_value
(name, role, values)Sets a field value name and role using a dictionary, as in the following:
set_field_value_array
(name, role, values_array)Sets an array of field values by name and role using an array of dictionaries, as in the following:
set_input
(name[, sample, item, value, …])Sets a input
FieldValue
to a value.set_input_array
(name, values)Sets input
FieldValue
array using values.set_output
(name[, sample, item, value, …])Sets a output
FieldValue
to a value.set_output_array
(name, values)Sets output
FieldValue
array using values.show
([pre])Print the operation nicely.
update_field_values
(value_dict[, role])where
(session, params)Finds a list of models by some parameters.
where_callback
(model_name, *args, **kwargs)Finds models using a model interface and a set of parameters.
Attributes
DEFAULT_COPY_KEEP_UNANONYMOUS
GLOBAL_KEY
METATYPE
PRIMARY_KEY
SERVER_MODEL_NAME
counter
Operation.data_associations
Operation.field_values
fields
id
Return a list of all input
FieldValues
Operation.job_associations
Operation.jobs
Operation.operation_type
Return a list of all output
FieldValues
plan
Operation.plan_associations
Operation.plans
predecessors
rid
- rtype
int
Operation.routing
The connected session instance.
Operation.status
successors
-
_check_for_session
()¶ Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo)¶ Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
()¶ Return the model’s data.
-
_get_deserialized_data
()¶ Return the deserialized model data.
-
_model_schema
¶ alias of
pydent.marshaller.base.OperationSchema
-
property
_primary_key
¶ Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
()¶ Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data)¶ Initializes fake attributes that correspond to data.
-
add_to_input_array
(name, sample=None, item=None, value=None, container=None)[source]¶ Creates and adds a new input
FieldValue
. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValue
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the newly created FieldValue
- Return type
-
add_to_output_array
(name, sample=None, item=None, value=None, container=None)[source]¶ Creates and adds a new output
FieldValue
. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValue
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the newly created FieldValue
- Return type
-
anonymize
()¶ Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model)¶ Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
associate
(key, value, upload=None, create_new=False, save=None)¶ Adds a data association with the key and value to this object.
- Parameters
key (str) – Key of the association
value (dict | str | int | float) – a json serializable object
upload (File) – optional file to upload
create_new – if True (default) will create a new association instead of updating the existing association.
- Tuype create_new
bool
- Returns
newly created or updated data association
- Return type
-
associate_file
(key, value, file, job_id=None)¶ Associate a file.
- Parameters
key (str or json) – association key
value (str or json) – association value
file (file object) – file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
associate_file_from_path
(key, value, filepath, job_id=None)¶ Associate a file from a filepath.
- Parameters
key (str or json) – association key
value (str or json) – association value
filepath (str) – path to file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
connect_to_session
(session)¶ Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None)¶ Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False)¶ Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
field_value
(name, role)[source]¶ Returns
FieldValue
with name and role.Return None if not found.
-
field_value_array
(name, role)[source]¶ Returns
FieldValue
array with name and role.
-
find_callback
(model_name, model_id)¶ Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name)¶ Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
get_field_type
(name, role)¶ Returns a
pydent.models.FieldType
by its name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
metatypes field type or None if not found
- Return type
FieldType | None
-
get_field_types
(name=None, role=None)¶ Returns a list of
pydent.models.FieldType
by their name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field types
- Return type
list
-
get_field_value
(name, role=None)¶ Returns a
pydent.models.FieldValue
by its name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
the field value or None if not found
- Return type
FieldValue | None
-
get_field_value_array
(name, role=None)¶ Returns a list of
pydent.models.FieldValue
by their name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field values
- Return type
list
-
get_metatype
()¶ Returns the instance’s metatype.
The metatype is either
pydent.models.SampleType
orpydent.models.OperationType
). The metatype class name is stored as METATYPE in the class definition.- Returns
the metatype
- Return type
-
get_routing
()[source]¶ Returns the routing dictionary for this instance.
- Returns
routing dictionary
- Return type
dict
-
init_field_values
()[source]¶ Initialize the
FieldValue
from theFieldType
of the parentOperation
type.
-
input
(name)[source]¶ Returns the input
FieldValue
by name.
-
property
inputs
¶ Return a list of all input
FieldValues
-
classmethod
interface
(session)¶ Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name)¶ Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs)¶ Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None)¶ Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
¶ alias of
pydent.marshaller.base.OperationSchema
-
new_field_value
(name, role=None, values_dict=None)¶ Instantiates a new
pydent.models.FieldValue
from a name and role. The should be a field type with the name and role in the metatype. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
name (basestring) – its name
role (basestring) – its role
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
new_field_value_from_field_type
(field_type, values_dict=None)¶ Instantiates a new
pydent.models.FieldValue
from a.pydent.models.FieldType
instance. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
field_type (FieldType) – field type to instantiate the field value
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
no_getter
(*_)¶ Callback that always returns None.
-
output
(name)[source]¶ Returns the output
FieldValue
by name.
-
property
outputs
¶ Return a list of all output
FieldValues
-
refresh
()¶ Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data)¶ Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name)¶ Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
safe_get_field_type
(fv)¶ Safely returns the field value’s
pydent.models.FieldType
from the model.If the field value has no reference to the field type, its metatype (e.g.
pydent.models.SampleType
orpydent.models.OperationType
) is used to recover the field type.
-
property
session
¶ The connected session instance.
-
set_field_value
(name, role, values)¶ Sets a field value name and role using a dictionary, as in the following:
values = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
-
set_field_value_array
(name, role, values_array)¶ Sets an array of field values by name and role using an array of dictionaries, as in the following:
values_array = [{ "value": None, "sample": mysample, "item": myitem, "object_type": None }]
-
set_input
(name, sample=None, item=None, value=None, container=None, object_type=None)[source]¶ Sets a input
FieldValue
to a value. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldValue/FieldType
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the existing FieldValue modified
- Return type
-
set_input_array
(name, values)[source]¶ Sets input
FieldValue
array using values. Values should be a list of dictionaries containing sample, item, container, or values keys. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValues being modified
values (list) – list of dictionary of values to set (e.g. [{“sample”: mysample}, {“item”: myitem}])
- Returns
the list of modified FieldValues
- Return type
list
-
set_output
(name, sample=None, item=None, value=None, container=None, object_type=None)[source]¶ Sets a output
FieldValue
to a value. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldValue/FieldType
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the existing FieldValue modified
- Return type
-
set_output_array
(name, values)[source]¶ Sets output
FieldValue
array using values. Values should be a list of dictionaries containing sample, item, container, or values keys. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValues being modified
values (list) – list of dictionary of values to set (e.g. [{“sample”: mysample}, {“item”: myitem}])
- Returns
the list of modified FieldValues
- Return type
list
-
property
uri
¶ Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-