Browse Source

Fixing component deletion

Yann Weber 9 years ago
parent
commit
ed9133016f

+ 2
- 6
EditorialModel/classes.py View File

@@ -42,18 +42,14 @@ class EmClass(EmComponent):
42 42
     ## @brief Delete a class if it's ''empty''
43 43
     # If a class has no fieldgroups delete it
44 44
     # @return bool : True if deleted False if deletion aborded
45
-    def delete(self):
45
+    def delete_check(self):
46 46
         for emtype in self.model.components(EmType):
47 47
             if emtype.class_id == self.uid:
48 48
                 return False
49 49
         for fieldgroup in self.model.components(EditorialModel.fieldgroups.EmFieldGroup):
50 50
             if fieldgroup.class_id == self.uid:
51 51
                 return False
52
-
53
-        if self.model.delete_component(self.uid):
54
-            return self.check()
55
-        else:
56
-            return False
52
+        return True
57 53
 
58 54
     ## Retrieve list of the field_groups of this class
59 55
     # @return A list of fieldgroups instance

+ 5
- 0
EditorialModel/components.py View File

@@ -99,6 +99,11 @@ class EmComponent(object):
99 99
                 component.rank = i + 1
100 100
         # No need to sort again here
101 101
 
102
+    ## @brief Delete predicate. Indicates if a component can be deleted
103
+    # @return True if deletion OK else return False
104
+    def delete_check(self):
105
+        raise NotImplementedError("Virtual method")
106
+
102 107
     ## @brief Get the maximum rank given an EmComponent child class and a ranked_in filter
103 108
     # @return A positive integer or -1 if no components
104 109
     def get_max_rank(self):

+ 3
- 7
EditorialModel/fieldgroups.py View File

@@ -31,17 +31,13 @@ class EmFieldGroup(EmComponent):
31 31
             raise EmComponentCheckError("class_id cointains an uid from a component that is not an EmClass but an "+type(em_class))
32 32
 
33 33
     ## Deletes a fieldgroup
34
-    # @return True if the deletion is a success, False if not
35
-    def delete(self):
34
+    # @return True if the deletion is possible, False if not
35
+    def delete_check(self):
36 36
         # all the EmField objects contained in this fieldgroup should be deleted first
37 37
         fieldgroup_fields = self.fields()
38 38
         if len(fieldgroup_fields) > 0:
39 39
             raise NotEmptyError("This Fieldgroup still contains fields. It can't be deleted then")
40
-        # then we delete this fieldgroup
41
-        if self.model.delete_component(self.uid):
42
-            return self.check()
43
-        else:
44
-            return False
40
+        return True
45 41
 
46 42
     ## Get the list of associated fields
47 43
     # if type_id, the fields will be filtered to represent selected fields of this EmType

+ 2
- 5
EditorialModel/fields.py View File

@@ -43,8 +43,5 @@ class EmField(EmComponent):
43 43
     ## @brief Delete a field if it's not linked
44 44
     # @return bool : True if deleted False if deletion aborded
45 45
     # @todo Check if unconditionnal deletion is correct
46
-    def delete(self):
47
-        if self.model.delete_component(self.uid):
48
-            return self.check()
49
-        else:
50
-            return False
46
+    def delete_check(self):
47
+        return True

+ 4
- 4
EditorialModel/model.py View File

@@ -153,11 +153,11 @@ class Model(object):
153 153
     def delete_component(self, uid):
154 154
         #register the deletion in migration handler
155 155
         self.migration_handler.register_change(uid, self.component(uid).attr_dump, None)
156
-
157
-        if uid not in self._components[uid]:
156
+        
157
+        em_component = self.component(uid)
158
+        if not em_component:
158 159
             raise EditorialModel.components.EmComponentNotExistError()
159
-        em_component = self._components[uid]
160
-        if em_component.delete_p():
160
+        if em_component.delete_check():
161 161
             self._components[self.name_from_emclass(em_component.__class__)].remove(em_component)
162 162
             del self._components['uids'][uid]
163 163
         return True

+ 2
- 5
EditorialModel/types.py View File

@@ -79,17 +79,14 @@ class EmType(EmComponent):
79 79
     # @return True if delete False if not deleted
80 80
     # @todo Check if the type is not linked by any EmClass
81 81
     # @todo Check if there is no other ''non-deletion'' conditions
82
-    def delete(self):
82
+    def delete_check(self):
83 83
         if sum(self.subordinates_list) > 0:
84 84
             return False
85 85
         #Delete all relation with superiors
86 86
         for nature, sups in self.superiors().items():
87 87
             for sup in sups:
88 88
                 self.del_superior(sup, nature)
89
-        if super(EmType, self).delete():
90
-            return self.check()
91
-        else:
92
-            return False
89
+        return True
93 90
 
94 91
     ## Get the list of non empty associated fieldgroups
95 92
     # @return A list of EmFieldGroup instance

Loading…
Cancel
Save