Browse Source

Add methos to classtype and type

Yann Weber 9 years ago
parent
commit
3b39b11f16
2 changed files with 29 additions and 0 deletions
  1. 8
    0
      EditorialModel/classtypes.py
  2. 21
    0
      EditorialModel/types.py

+ 8
- 0
EditorialModel/classtypes.py View File

8
     PARENT = 'parent'
8
     PARENT = 'parent'
9
     TRANSLATION = 'translation'
9
     TRANSLATION = 'translation'
10
     IDENTITY = 'identity'
10
     IDENTITY = 'identity'
11
+    
12
+    @classmethod
13
+    def getall(cls):
14
+        return [ cls.PARENT, cls.TRANSLATION, cls.IDENTITY ]
11
 
15
 
12
 
16
 
13
 ## EmClassType (Class)
17
 ## EmClassType (Class)
76
             },
80
             },
77
         },
81
         },
78
     }
82
     }
83
+    
84
+    @classmethod
85
+    def getall(cls):
86
+        return [ cls.entity, cls.entry, cls.person ]
79
 
87
 
80
     ## natures (Method)
88
     ## natures (Method)
81
     #
89
     #

+ 21
- 0
EditorialModel/types.py View File

213
     def superiors(self):
213
     def superiors(self):
214
         return {nature: [self.model.component(superior_uid) for superior_uid in superiors_uid] for nature, superiors_uid in self.superiors_list.items()}
214
         return {nature: [self.model.component(superior_uid) for superior_uid in superiors_uid] for nature, superiors_uid in self.superiors_list.items()}
215
 
215
 
216
+    ## @brief Given a relation's nature return all the possible type to add as superiors
217
+    # @param relation_nature str | None : if None check for all natures
218
+    # @return a list or a dict with nature as key
219
+    def possible_superiors(self, relation_nature = None):
220
+        if relation_nature is None:
221
+            ret = {}
222
+            for nat in EmNature.getall():
223
+                ret[nat] = self.possible_superiors(nat)
224
+            return ret
225
+
226
+        #One nature
227
+        if relation_nature not in self.classtype['hierarchy']:
228
+            return []
229
+
230
+        att = self.classtype['hierarchy'][relation_nature]['attach']
231
+        if att == 'type':
232
+            return [ self ]
233
+        else:
234
+           return [ t for t in self.model.components(EmType) if t.classtype == self.classtype ]
235
+
236
+
216
     ## Add a superior in the type hierarchy
237
     ## Add a superior in the type hierarchy
217
     # @param em_type EmType: An EmType instance
238
     # @param em_type EmType: An EmType instance
218
     # @param relation_nature str: The name of the relation's nature
239
     # @param relation_nature str: The name of the relation's nature

Loading…
Cancel
Save