diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index efd4a3e7af55297588bf03f869f18846d991f3f0..3b225b337b987afef38192d8d33b2d5d88e57769 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -429,16 +429,37 @@ class Entity(object): return self def add_parent(self, parent=None, **kwargs): # @ReservedAssignment - """Add a parent to this entity. + """Add a parent to this entity + + Parameters + ---------- + parent : Entity or int or str or None + The parent entity, either specified by the Entity object + itself, or its id or its name. Default is None. + **kwargs : dict, optional + Additional keyword arguments for specifying the parent by + name or id, and for specifying the mode of inheritance. + + id : int + Integer id of the parent entity. Ignored if `parent` + is not None. + name : str + Name of the parent entity. Ignored if `parent is not + none`. + inheritance : str + One of `"obligatory"`, `"recommended"`, `"suggested"`, + or `"fix"`. Specifies the importance of the properties + of the parent that will be inherited by this + entity. If no `inheritance` is given, no properties + will be inherited by the child. + + Raises + ------ + UserWarning + If neither a 'parent' parameter, nor the 'id', nor 'name' + parameter is passed to this method. - The first parameter is meant to identify the parent entity. So the method expects an instance of - Entity, an integer or a string here. Even though, by means of the **kwargs parameter you may pass - more parameters to this method. Accepted keywords are: id, name, inheritance. Any other keyword is - ignored right now but this may change in the future. - @param parent: An entity, an id or a name. - @param **kwargs: Accepted keywords: id, name, inheritance. - @raise UserWarning: If neither a 'parent' parameter, nor the 'id', nor 'name' parameter is passed to this method. """ name = (kwargs['name'] if 'name' in kwargs else None) pid = (kwargs['id'] if 'id' in kwargs else None) @@ -1435,6 +1456,23 @@ class Property(Entity): property=property, value=value, **copy_kwargs) def add_parent(self, parent=None, **kwargs): + """Add a parent Entity to this Property. + + Parameters + ---------- + parent : Entity or int or str or None, optional + The parent entity + **kwargs : dict, optional + Additional keyword arguments specifying the parent Entity + by id or name, and specifying the inheritance level. See + :py:meth:`Entity.add_parent` for more information. Note + that by default, `inheritance` is set to `FIX`. + + See Also + -------- + Entity.add_parent + + """ copy_kwargs = kwargs.copy() if 'inheritance' not in copy_kwargs: @@ -1513,6 +1551,24 @@ class RecordType(Entity): **copy_kwargs) def add_parent(self, parent=None, **kwargs): + """Add a parent to this RecordType + + Parameters + ---------- + parent : Entity or int or str or None, optional + The parent entity, either specified by the Entity object + itself, or its id or its name. Default is None. + **kwargs : dict, optional + Additional keyword arguments specifying the parent Entity by id or + name, and specifying the inheritance level. See + :py:meth:`Entity.add_parent` for more information. Note + that by default, `inheritance` is set to `OBLIGATORY`. + + See Also + -------- + Entity.add_parent + + """ copy_kwargs = kwargs.copy() if 'inheritance' not in copy_kwargs: diff --git a/src/caosdb/exceptions.py b/src/caosdb/exceptions.py index f02a4630356726f99d8439fd821b6dd327ab22c7..fdd2e11f1dfb8857f86942df2534d732bad9a793 100644 --- a/src/caosdb/exceptions.py +++ b/src/caosdb/exceptions.py @@ -189,8 +189,8 @@ class TransactionError(CaosDBException): error_t. If direct_children_only is True, only direct children are checked. - Parameters: - ----------- + Parameters + ---------- error_t : EntityError error type to be checked direct_children_only: bool, optional @@ -199,8 +199,8 @@ class TransactionError(CaosDBException): children, i.e., all errors in self.all_errors are used. Default is false. - Returns: - -------- + Returns + ------- has_error : bool True if at least one of the children is of type error_t, False otherwise. diff --git a/src/doc/tutorials/Data-Insertion.rst b/src/doc/tutorials/Data-Insertion.rst index 22a5548b1827b1b9bda765b155b539ceba8a822a..e0ea62e3e7d6bbb8b9e78cb916fee88bd7956209 100644 --- a/src/doc/tutorials/Data-Insertion.rst +++ b/src/doc/tutorials/Data-Insertion.rst @@ -40,7 +40,10 @@ Inheritance of Properties ------------------------- Suppose you want to insert a new RecordType “2D_BarkleySimulation” -that denotes spatially extended Barkley simulations. +that denotes spatially extended Barkley simulations. This is a subtype +of the “BarkleySimulation” RecordType above and should have all its +parameters, i.e., properties. It may be assigned more, e.g., spatial +resolution, but we'll omit this for the sake of brevity for now. .. code:: python @@ -53,12 +56,15 @@ that denotes spatially extended Barkley simulations. print(rt.get_property(name="epsilon").importance) ### rt has a "epsilon" property with the same importance as "BarkleySimulation" The parameter ``inheritance=(obligatory|recommended|fix|all|none)`` of -``add_parent`` tells the server to assign obligatory:: properties of the -parent to the child automatically, recommended:: properties of the -parent to the child automatically, fix:: properties of the parent to the -child automatically, all:: properties of the parent to the child -automatically, none:: of the properties of the parent to child -automatically, +``add_parent`` tells the server to assign all properties of the parent +RecordType with the chosen importance to the child RecordType +automatically upon insertion. + +.. note:: + + The inherited properties will only be present after the insertion + since they have to be set by the CaosDB server, not by the Python + Client. Insert Actual Data