|
@@ -99,7 +99,7 @@ class LeType(object):
|
99
|
99
|
def del_superior(self, leo, nature):
|
100
|
100
|
if nature is None:
|
101
|
101
|
raise ValueError('The argument nature cannot be None')
|
102
|
|
- return self._datasource(leo.lodel_id, self.lodel_id, nature)
|
|
102
|
+ return self._datasource(leo, self, nature)
|
103
|
103
|
|
104
|
104
|
## @brief Get the linked objects lodel_id
|
105
|
105
|
# @return an array of lodel_id linked with this object
|
|
@@ -110,20 +110,28 @@ class LeType(object):
|
110
|
110
|
## @brief Link this object with a LeObject
|
111
|
111
|
# @note rel2type
|
112
|
112
|
# @param leo LeObject : The object to be linked with
|
|
113
|
+ # @param **rel_attr : keywords arguments for relations attributes
|
113
|
114
|
# @return True if success False allready done
|
114
|
115
|
# @throw A Leo exception if the link is not allowed
|
115
|
116
|
# @todo unit tests
|
116
|
117
|
# @todo find a value for depth and rank....
|
117
|
|
- def link_to(self, leo):
|
118
|
|
- if leo.__class__ not in self._linked_types:
|
|
118
|
+ def link_to(self, leo, **rel_attr):
|
|
119
|
+ if leo.__class__ not in self._linked_types.keys():
|
119
|
120
|
raise leobject.leobject.LeObjectError("Constraint error : %s cannot be linked with %s"%(self.__class__.__name__, leo.__class__.__name__))
|
120
|
|
- return self._datasource.add_relation(self.lodel_id, leo.lodel_id)
|
|
121
|
+
|
|
122
|
+ for attr_name in rel_attr.keys():
|
|
123
|
+ if attr_name not in [ f for f,g in self._linked_types[leo.__class__] ]:
|
|
124
|
+ raise AttributeError("A rel2type between a %s and a %s doesn't have an attribute %s"%(self.__class__.__name__, leo.__class__.__name__, attr_name))
|
|
125
|
+ if not self._linked_types[leo.__class__][1].check(rel_attr[attr_name]):
|
|
126
|
+ raise ValueError("Wrong value '%s' for attribute %s"%(rel_attr[attr_name], attr_name))
|
|
127
|
+
|
|
128
|
+ return self._datasource.add_relation(self, leo, nature=None, depth=None, rank=None, **rel_attr)
|
121
|
129
|
|
122
|
130
|
## @brief Remove a link bewteen this object and another
|
123
|
131
|
# @param leo LeObject : A LeObject instance linked with self
|
124
|
132
|
# @todo unit tests
|
125
|
133
|
def unlink(self, leo):
|
126
|
|
- return self._datasource.del_relation(self.lodel_id, leo.lodel_id)
|
|
134
|
+ return self._datasource.del_relation(self, leo)
|
127
|
135
|
|
128
|
136
|
## @brief Delete a LeType from the datasource
|
129
|
137
|
# @param filters list : list of filters (see @ref leobject_filters)
|