Module for the Django backend implementation of the AuthInfo ORM class.
aiida.orm.implementation.django.authinfos.
DjangoAuthInfo
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.authinfos.BackendAuthInfo
aiida.orm.implementation.django.entities.DjangoModelEntity
aiida.orm.implementation.authinfos.BackendAuthInfo
Django backend implementation for the AuthInfo ORM class.
MODEL_CLASS
alias of aiida.backends.djsite.db.models.DbAuthInfo
aiida.backends.djsite.db.models.DbAuthInfo
__abstractmethods__
__init__
Construct a new instance.
computer – a aiida.orm.implementation.computers.BackendComputer instance
aiida.orm.implementation.computers.BackendComputer
user – a aiida.orm.implementation.users.BackendUser instance
aiida.orm.implementation.users.BackendUser
an aiida.orm.implementation.authinfos.BackendAuthInfo instance
__module__
__orig_bases__
__parameters__
_abc_impl
computer
Return the computer associated with this instance.
enabled
Return whether this instance is enabled.
boolean, True if enabled, False otherwise
get_auth_params
Return the dictionary of authentication parameters
a dictionary with authentication parameters
get_metadata
Return the dictionary of metadata
a dictionary with metadata
id
Return the id for this entity.
This is unique only amongst entities of this type for a particular backend.
the entity id
is_stored
Return whether the entity is stored.
True if stored, False otherwise
bool
set_auth_params
Set the dictionary of authentication parameters
auth_params – a dictionary with authentication parameters
set_metadata
Set the dictionary of metadata
metadata – a dictionary with metadata
store
Store and return the instance.
user
Return the user associated with this instance.
DjangoAuthInfoCollection
Bases: aiida.orm.implementation.authinfos.BackendAuthInfoCollection
aiida.orm.implementation.authinfos.BackendAuthInfoCollection
The collection of Django backend AuthInfo entries.
ENTITY_CLASS
alias of DjangoAuthInfo
delete
Delete an entry from the collection.
pk – the pk of the entry to delete
get
Return an entry from the collection that is configured for the given computer and user
aiida.common.exceptions.NotExistent – if no entry exists for the computer/user pair
aiida.common.exceptions.MultipleObjectsError – if multiple entries exist for the computer/user pair
Django implementation of aiida.orm.implementation.backends.Backend.
aiida.orm.implementation.django.backend.
DjangoBackend
Bases: aiida.orm.implementation.sql.backends.SqlBackend
aiida.orm.implementation.sql.backends.SqlBackend
Construct the backend instance by initializing all the collections.
authinfos
Return the collection of authorisation information objects
the authinfo collection
aiida.orm.implementation.BackendAuthInfoCollection
comments
Return the collection of comments
the comment collection
aiida.orm.implementation.BackendCommentCollection
computers
Return the collection of computers
the computers collection
aiida.orm.implementation.BackendComputerCollection
cursor
Return a psycopg cursor to be used in a context manager.
a psycopg cursor
psycopg2.extensions.cursor
execute_raw
Execute a raw SQL statement and return the result.
query – a string containing a raw SQL statement
the result of the query
get_backend_entity
Return a BackendEntity instance from a DbModel instance.
get_connection
Get the Django connection
the django connection
get_session
Return a database session that can be used by the QueryBuilder to perform its query.
If there is an exception within the context then the changes will be rolled back and the state will be as before entering. Transactions can be nested.
an instance of sqlalchemy.orm.session.Session
sqlalchemy.orm.session.Session
groups
Return the collection of groups
the groups collection
aiida.orm.implementation.BackendGroupCollection
logs
Return the collection of logs
the log collection
aiida.orm.implementation.BackendLogCollection
migrate
Migrate the database to the latest schema generation or version.
nodes
Return the collection of nodes
the nodes collection
aiida.orm.implementation.BackendNodeCollection
query
Return an instance of a query builder implementation for this backend
a new query builder instance
aiida.orm.implementation.BackendQueryBuilder
query_manager
Return the query manager for the objects stored in the backend
The query manger
aiida.backends.general.abstractqueries.AbstractQueryManager
transaction
Open a transaction to be used as a context manager.
users
Return the collection of users
the users collection
aiida.orm.implementation.BackendUserCollection
Django implementations for the Comment entity and collection.
aiida.orm.implementation.django.comments.
DjangoComment
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.comments.BackendComment
aiida.orm.implementation.comments.BackendComment
Comment implementation for Django.
alias of aiida.backends.djsite.db.models.DbComment
aiida.backends.djsite.db.models.DbComment
Construct a DjangoComment.
node – a Node instance
user – a User instance
content – the comment content
ctime – The creation time as datetime object
mtime – The modification time as datetime object
a Comment object associated to the given node and user
_auto_flush
content
ctime
mtime
node
set_content
set_mtime
set_user
Can only store if both the node and user are stored as well.
DjangoCommentCollection
Bases: aiida.orm.implementation.comments.BackendCommentCollection
aiida.orm.implementation.comments.BackendCommentCollection
Django implementation for the CommentCollection.
alias of DjangoComment
create
Create a Comment for a given node and user
Remove a Comment from the collection with the given id
comment_id (int) – the id of the comment to delete
TypeError – if comment_id is not an int
comment_id
NotExistent – if Comment with ID comment_id is not found
delete_all
Delete all Comment entries.
IntegrityError – if all Comments could not be deleted
delete_many
Delete Comments based on filters
filters
filters (dict) – similar to QueryBuilder filter
(former) PK s of deleted Comments
PK
list
TypeError – if filters is not a dict
ValidationError – if filters is empty
Django implementations for the Computer entity and collection.
aiida.orm.implementation.django.computers.
DjangoComputer
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.computers.BackendComputer
Django implementation for BackendComputer.
alias of aiida.backends.djsite.db.models.DbComputer
aiida.backends.djsite.db.models.DbComputer
Construct a new DjangoComputer instance.
copy
Create an unstored clone of an already stored Computer.
description
get_description
get_hostname
Get this computer hostname :rtype: str
get_name
get_scheduler_type
get_transport_type
hostname
Is this entity stored?
name
set_description
set_hostname
Set the hostname of this computer :param val: The new hostname :type val: str
Set the metadata.
set_name
set_scheduler_type
set_transport_type
Store the Computer instance.
uuid
DjangoComputerCollection
Bases: aiida.orm.implementation.computers.BackendComputerCollection
aiida.orm.implementation.computers.BackendComputerCollection
Collection of Computer instances.
alias of DjangoComputer
Delete the computer with the given pk.
list_names
Module to get an ORM backend instance from a database model instance.
aiida.orm.implementation.django.convert.
Default get_backend_entity from DbModel
dbmodel – the db model instance
Classes and methods for Django specific backend entities
aiida.orm.implementation.django.entities.
DjangoModelEntity
Bases: typing.Generic
typing.Generic
A mixin that adds some common Django backend entity methods
__dict__
Initialize self. See help(type(self)) for accurate signature.
__weakref__
list of weak references to the object (if defined)
_class_check
Assert that the class is correctly configured
_dbmodel
dbmodel
from_dbmodel
Create a DjangoEntity from the corresponding db model class
dbmodel – the model to create the entity from
backend – the corresponding backend
the Django entity
get_dbmodel_attribute_name
Given the name of an attribute of the entity class give the corresponding name of the attribute in the db model. It if doesn’t exit this raises a ValueError
attr_name –
the dbmodel attribute name
str
Store the entity
the entity itself
Django Group entity
aiida.orm.implementation.django.groups.
DjangoGroup
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.groups.BackendGroup
aiida.orm.implementation.groups.BackendGroup
The Django group object
alias of aiida.backends.djsite.db.models.DbGroup
aiida.backends.djsite.db.models.DbGroup
Construct a new Django group
__int__
Convert the class to an integer. This is needed to allow querying with Django. Be careful, though, not to pass it to a wrong field! This only returns the local DB principal key (pk) value.
the integer pk of the node or None if not stored.
add_nodes
Add a set of nodes to the group.
all the nodes and the group itself have to be stored.
nodes – a list of BackendNode instances to be added to this group
clear
Remove all the nodes from this group.
count
Return the number of entities in this group.
integer number of entities contained within the group
the description of the group as a string
label
the name of the group as a string
Get an iterator to the nodes in the group
remove_nodes
Remove a set of nodes from the group.
nodes – a list of BackendNode instances to be removed from this group
type_string
the string defining the type of the group
a backend user object, representing the user associated to this group.
aiida.orm.implementation.BackendUser
a string with the uuid
DjangoGroupCollection
Bases: aiida.orm.implementation.groups.BackendGroupCollection
aiida.orm.implementation.groups.BackendGroupCollection
The Django Group collection
alias of DjangoGroup
Delete a group with the given id
id – the id of the group to delete
Query for groups.
By default, query for user-defined groups only (type_string==””). If you want to query for all type of groups, pass type_string=None. If you want to query for a specific type of groups, pass a specific string as the type_string argument.
name – the name of the group
nodes – a node or list of nodes that belongs to the group (alternatively, you can also pass a DbNode or list of DbNodes)
pk – the pk of the group
uuid – the uuid of the group
type_string – the string for the type of node; by default, look only for user-defined groups (see note above).
user – by default, query for groups of all users; if specified, must be a DbUser object, or a string for the user email.
past_days – by default, query for all groups; if specified, query the groups created in the last past_days. Must be a datetime object.
name_filters – dictionary that can contain ‘startswith’, ‘endswith’ or ‘contains’ as keys
node_attributes – if not None, must be a dictionary with format {k: v}. It will filter and return only groups where there is at least a node with an attribute with key=k and value=v. Different keys of the dictionary are joined with AND (that is, the group should satisfy all requirements. v can be a base data type (str, bool, int, float, …) If it is a list or iterable, that the condition is checked so that there should be at least a node in the group with key=k and value=each of the values of the iterable.
kwargs –
any other filter to be passed to DbGroup.objects.filter
node_attributes = {'elements': ['Ba', 'Ti'], 'md5sum': 'xxx'}
it will find groups that contain the node with md5sum = ‘xxx’, and moreover contain at least one node for element ‘Ba’ and one node for element ‘Ti’.
The Django log and log collection module
aiida.orm.implementation.django.logs.
DjangoLog
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.logs.BackendLog
aiida.orm.implementation.logs.BackendLog
Django Log backend class
alias of aiida.backends.djsite.db.models.DbLog
aiida.backends.djsite.db.models.DbLog
dbnode_id
Get the id of the object that created the log entry
levelname
The name of the log level
loggername
The name of the logger that created this entry
message
Get the message corresponding to the entry
metadata
Get the metadata corresponding to the entry
time
Get the time corresponding to the entry
Get the string representation of the uuid of the object that created the log entry
DjangoLogCollection
Bases: aiida.orm.implementation.logs.BackendLogCollection
aiida.orm.implementation.logs.BackendLogCollection
Django log collection
alias of DjangoLog
Remove a Log entry from the collection with the given id
log_id (int) – id of the Log to delete
TypeError – if log_id is not an int
log_id
NotExistent – if Log with ID log_id is not found
Delete all Log entries.
IntegrityError – if all Logs could not be deleted
Delete Logs based on filters
(former) PK s of deleted Logs
Django implementation of the BackendNode and BackendNodeCollection classes.
aiida.orm.implementation.django.nodes.
DjangoNode
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.nodes.BackendNode
aiida.orm.implementation.nodes.BackendNode
Django Node backend entity
LINK_CLASS
alias of aiida.backends.djsite.db.models.DbLink
aiida.backends.djsite.db.models.DbLink
alias of aiida.backends.djsite.db.models.DbNode
aiida.backends.djsite.db.models.DbNode
Construct a new BackendNode instance wrapping a new DbNode instance.
backend – the backend
node_type – the node type string
user – associated BackendUser
computer – associated BackendComputer
label – string label
description – string description
_add_link
Add a link of the given type from a given node to ourself.
source – the node from which the link is coming
link_type – the link type
link_label – the link label
add_incoming
True if the proposed link is allowed, False otherwise
aiida.common.ModificationNotAllowed – if either source or target node is not stored
clean_values
clone
Return an unstored clone of ourselves.
an unstored BackendNode with the exact same attributes and extras as self
Return the computer of this node.
the computer or None
BackendComputer or None
Store the node in the database.
links – optional links to add before storing
with_transaction – if False, do not use a transaction because the caller will already have opened one.
clean – boolean, if True, will clean the attributes and extras before attempting to store
Return the user of this node.
the user
BackendUser
DjangoNodeCollection
Bases: aiida.orm.implementation.nodes.BackendNodeCollection
aiida.orm.implementation.nodes.BackendNodeCollection
The collection of Node entries.
alias of DjangoNode
Remove a Node entry from the collection with the given id
pk – id of the node to delete
Return a Node entry from the collection with the given id
pk – id of the node
Django query builder
aiida.orm.implementation.django.querybuilder.
DjangoQueryBuilder
Bases: aiida.orm.implementation.querybuilder.BackendQueryBuilder
aiida.orm.implementation.querybuilder.BackendQueryBuilder
AuthInfo
A property, decorated with @property. Returns the implementation for the AuthInfo
Comment
A property, decorated with @property. Returns the implementation for the Comment
Computer
A property, decorated with @property. Returns the implementation for the Computer
Group
A property, decorated with @property. Returns the implementation for the Group
Link
A property, decorated with @property. Returns the implementation for the DbLink
Log
A property, decorated with @property. Returns the implementation for the Log
Node
Decorated as a property, returns the implementation for DbNode. It needs to return a subclass of sqlalchemy.Base, which means that for different ORM’s a corresponding dummy-model must be written.
User
A property, decorated with @property. Returns the implementation for the User
get_column_names
Given the backend specific alias, return the column names that correspond to the aliased table.
get_filter_expr
Applies a filter on the alias given. Expects the alias of the ORM-class on which to filter, and filter_spec. Filter_spec contains the specification on the filter. Expects:
operator – The operator to apply, see below for further details
value – The value for the right side of the expression, the value you want to compare with.
path – The path leading to the value
attr_key – Boolean, whether the value is in a json-column, or in an attribute like table.
Implemented and valid operators:
for any type: * == (compare single value, eg: ‘==’:5.0) * in (compare whether in list, eg: ‘in’:[5, 6, 34]
>
<
<=
>=
like (case - sensitive), for example ‘like’:’node.calc.%’ will match node.calc.relax and node.calc.RELAX and node.calc. but not node.CALC.relax
ilike (case - unsensitive) will also match node.CaLc.relax in the above example
Note
The character % is a reserved special character in SQL, and acts as a wildcard. If you specifically want to capture a % in the string, use: _%
%
_%
for arrays and dictionaries (only for the SQLAlchemy implementation):
contains: pass a list with all the items that the array should contain, or that should be among the keys, eg: ‘contains’: [‘N’, ‘H’])
has_key: pass an element that the list has to contain or that has to be a key, eg: ‘has_key’:’N’)
of_length
longer
shorter
All the above filters invoke a negation of the expression if preceded by ~:
# first example: filter_spec = { 'name' : { '~in':[ 'halle', 'lujah' ] } # Name not 'halle' or 'lujah' } # second example: filter_spec = { 'id' : { '~==': 2 } } # id is not 2
get_filter_expr_from_attributes
Returns an valid SQLAlchemy expression.
operator – The operator provided by the user (‘==’, ‘>’, …)
value – The value to compare with, e.g. (5.0, ‘foo’, [‘a’,’b’])
attr_key (str) – The path to that attribute as a tuple of values. I.e. if that attribute I want to filter by is the 2nd element in a list stored under the key ‘mylist’, this is (‘mylist’, ‘2’).
column – Optional, an instance of sqlalchemy.orm.attributes.InstrumentedAttribute or
column_name (str) – The name of the column, and the backend should get the InstrumentedAttribute.
alias – The aliased class.
An instance of sqlalchemy.sql.elements.BinaryExpression
get_table_name
Returns the table name given an Aliased class based on Aldjemy
modify_expansions
For django, there are no additional expansions for now, so I am returning an empty list
table_groups_nodes
A property, decorated with @property. Returns the implementation for the many-to-many relationship between group and nodes.
array_length
Bases: sqlalchemy.sql.functions.FunctionElement
sqlalchemy.sql.functions.FunctionElement
_compiler_dispatcher
compile
Get length of array defined in a JSONB column
jsonb_array_length
jsonb_typeof
Django user module
aiida.orm.implementation.django.users.
DjangoUser
Bases: aiida.orm.implementation.django.entities.DjangoModelEntity, aiida.orm.implementation.users.BackendUser
The Django user class
alias of aiida.backends.djsite.db.models.DbUser
aiida.backends.djsite.db.models.DbUser
email
Get the email address of the user
the email address
first_name
Get the user’s first name
the first name
institution
Get the user’s institution
the institution
last_name
Get the user’s last name
the last name
DjangoUserCollection
Bases: aiida.orm.implementation.users.BackendUserCollection
aiida.orm.implementation.users.BackendUserCollection
The Django collection of users
alias of DjangoUser
Create a user with the provided email address
A new user object
aiida.orm.implementation.django.users.DjangoUser
find
Find users in this collection
email – optional email address filter
id – optional id filter
a list of the found users
Utilities for the implementation of the Django backend.
aiida.orm.implementation.django.utils.
ModelWrapper
Bases: object
object
Wrap a database model instance to correctly update and flush the data model when getting or setting a field.
If the model is not stored, the behavior of the get and set attributes is unaltered. However, if the model is stored, which is to say, it has a primary key, the getattr and setattr are modified as follows:
getattr: if the item corresponds to a mutable model field, the model instance is refreshed first
setattr: if the item corresponds to a mutable model field, changes are flushed after performing the change
__getattr__
Get an attribute of the model instance.
If the model is saved in the database, the item corresponds to a mutable model field and the current scope is not in an open database connection, then the field’s value is first refreshed from the database.
item – the name of the model field
the value of the model’s attribute
Construct the ModelWrapper.
model – the database model instance to wrap
auto_flush – an optional tuple of database model fields that are always to be flushed, in addition to the field that corresponds to the attribute being set through __setattr__.
__setattr__
Set the attribute on the model instance.
If the field being set is a mutable model field and the model is saved, the changes are flushed.
key – the name of the model field
value – the value to set
_ensure_model_uptodate
Refresh all fields of the wrapped model instance by fetching the current state of the database instance.
fields – optionally refresh only these fields, if None all fields are refreshed.
_flush
Flush the fields of the model to the database.
If the wrapped model is not actually saved in the database yet, this method is a no-op.
fields – the model fields whose current value to flush to the database
_in_transaction
Return whether the current scope is within an open database transaction.
boolean, True if currently in open transaction, False otherwise.
_is_model_field
Return whether the field is a field of the model.
boolean, True if the field is a model field, False otherwise.
_is_mutable_model_field
Return whether the field is a mutable field of the model.
boolean, True if the field is a model field and is not in the IMMUTABLE_MODEL_FIELDS set.
is_saved
Retun whether the wrapped model instance is saved in the database.
boolean, True if the model is saved in the database, False otherwise
save
Store the model instance.
aiida.common.IntegrityError – if a database integrity error is raised during the save.