|
@@ -95,6 +95,40 @@ class _LeType(_LeClass):
|
95
|
95
|
## @brief Delete current instance from DB
|
96
|
96
|
def delete(self):
|
97
|
97
|
_LeCrud._delete(self)
|
|
98
|
+
|
|
99
|
+ ## @brief Add a superior
|
|
100
|
+ # @param lesup LeObject : LeObject child class instance
|
|
101
|
+ # @param nature str : Relation nature
|
|
102
|
+ # @param del_if_exists bool : If true delete the superior if any before setting the new one
|
|
103
|
+ # @return relation id if successfully created else returns false
|
|
104
|
+ def add_superior(self, lesup, nature, del_if_exists = False):
|
|
105
|
+ lehierarch = self.name2class('LeHierarch')
|
|
106
|
+ if del_if_exists:
|
|
107
|
+ prev_sup = lehierarch.get(
|
|
108
|
+ [('lesub', '=', self), ('nature', '=', nature)],
|
|
109
|
+ [ lehierarch.uidname() ]
|
|
110
|
+ )
|
|
111
|
+ if len(prev_sup) > 0:
|
|
112
|
+ for todel_sup in prev_sup: #This loop shoud be useless...but we never know
|
|
113
|
+ todel_sup.delete()
|
|
114
|
+
|
|
115
|
+ return lehierarch.insert(lesup = lesup, lesub = self, nature = nature)
|
|
116
|
+
|
|
117
|
+ ## @brief Link the LeObject with another one (rel2type relations)
|
|
118
|
+ #
|
|
119
|
+ # @note This methods asser that self is the superior and leo_tolink the subordinate
|
|
120
|
+ #
|
|
121
|
+ # @param leo_tolink LeObject : LeObject child instance to link with
|
|
122
|
+ # @param **datas : Relation attributes (if any)
|
|
123
|
+ # @return a relation id if success
|
|
124
|
+ def link_with(self, leo_tolink, **datas):
|
|
125
|
+ # Fetch rel2type leapi class
|
|
126
|
+ r2t = self.name2class('LeRel2Type')
|
|
127
|
+ r2tcls = self.name2class(r2t.relname(self, leo_tolink))
|
|
128
|
+ if not r2tcls:
|
|
129
|
+ raise ValueError("No rel2type possible between a '%s' as superior and a '%s' as subordinate" % (self._leclass.__name__, leo_tolink.__class__.__name__))
|
|
130
|
+ return r2tcls.insert(lesup = self, lesub = leo_tolink, **datas)
|
|
131
|
+
|
98
|
132
|
|
99
|
133
|
## @brief Get the linked objects lodel_id
|
100
|
134
|
# @param letype LeType : Filter the result with LeType child class (not instance)
|