Browse Source

Implements _LeObject.link_remove() and LeType.unlink_subordinate()

Yann Weber 9 years ago
parent
commit
a5996dc419
2 changed files with 28 additions and 0 deletions
  1. 21
    0
      leobject/leobject.py
  2. 7
    0
      leobject/letype.py

+ 21
- 0
leobject/leobject.py View File

@@ -144,6 +144,9 @@ class _LeObject(object):
144 144
     # @throw LeObjectError if the link is not valid
145 145
     # @throw AttributeError if an non existing relation attribute is given as argument
146 146
     # @throw ValueError if the relation attrivute value check fails
147
+    # 
148
+    # @todo Code factorisation on relation check
149
+    # @todo unit tests
147 150
     @classmethod
148 151
     def link_together(cls, lesup, lesub, **rel_attr):
149 152
         if lesub.__class__ not in lesup._linked_types.keys():
@@ -162,6 +165,9 @@ class _LeObject(object):
162 165
     # @param leo_is_superior bool : if True leo is the superior in the relation
163 166
     # @return A dict with LeType child class instance as key and dict {rel_attr_name:rel_attr_value, ...}
164 167
     # @throw LeObjectError if the relation is not possible
168
+    # 
169
+    # @todo Code factorisation on relation check
170
+    # @todo unit tests
165 171
     @classmethod
166 172
     def linked_together(cls, leo, letype, leo_is_superior = True):
167 173
         valid_link = letype in leo._linked_types.keys() if leo_is_superior else leo.__class__ in letype._linked_types.keys()
@@ -174,6 +180,21 @@ class _LeObject(object):
174 180
 
175 181
         return cls._datasource.get_related(leo, letype, leo_is_superior)
176 182
     
183
+    ## @brief Remove a link (and attributes) between two LeObject
184
+    # @param lesup LeType : LeType child instance
185
+    # @param lesub LeType : LeType child instance
186
+    # @return True if a link has been deleted
187
+    # @throw LeObjectError if the relation between the two LeObject is not possible
188
+    #
189
+    # @todo Code factorisation on relation check
190
+    # @todo unit tests
191
+    @classmethod
192
+    def link_remove(cls, lesup, lesub):
193
+        if lesub.__class__ not in lesup._linked_types.keys():
194
+            raise LeObjectError("Relation errorr : %s cannot be linked with %s"%(lesup.__class__.__name__, lesub.__class__.__name__))
195
+
196
+        return cls._datasource.del_related(lesup, lesub)
197
+    
177 198
     ## @brief Prepare a field_list
178 199
     # @param field_list list : List of string representing fields
179 200
     # @param letype LeType : LeType child class

+ 7
- 0
leobject/letype.py View File

@@ -138,6 +138,13 @@ class LeType(object):
138 138
     def linked_subordinates(self, letype):
139 139
         return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, letype, True)
140 140
 
141
+    ## @brief Remove a link with a subordinate
142
+    # @param leo LeType : LeType child instance
143
+    # @return True if a link has been deleted
144
+    # @throw LeObjectError if the relation between the two LeObject is not possible
145
+    def unlink_subordinate(self, leo):
146
+        return leobject.lefactory.LeFactory.leobj_from_name('LeObject').linked_together(self, leo)
147
+
141 148
     ## @brief Remove a link bewteen this object and another
142 149
     # @param leo LeType : LeType child class instance
143 150
     # @todo unit tests

Loading…
Cancel
Save