Browse Source

EmType : subordinates_list and fields_list

ArnAud 9 years ago
parent
commit
886cee22df
3 changed files with 21 additions and 20 deletions
  1. 2
    2
      EditorialModel/fieldgroups.py
  2. 3
    3
      EditorialModel/test/me.json
  3. 16
    15
      EditorialModel/types.py

+ 2
- 2
EditorialModel/fieldgroups.py View File

@@ -48,12 +48,12 @@ class EmFieldGroup(EmComponent):
48 48
             em_type = self.model.component(type_id)
49 49
             fields = []
50 50
             for field in self.model.components(EmField):
51
-                if field.fieldgroup_id != self.uid or (field.optional and field.uid not in em_type.selected_fields):
51
+                if field.fieldgroup_id != self.uid or (field.optional and field.uid not in em_type.fields_list):
52 52
                     continue
53 53
                 # don't include relational field if parent should not be included
54 54
                 if field.rel_field_id:
55 55
                     parent = self.model.component(field.rel_field_id)
56
-                    if parent.optional and parent.uid not in em_type.selected_fields:
56
+                    if parent.optional and parent.uid not in em_type.fields_list:
57 57
                         continue
58 58
                 fields.append(field)
59 59
 

+ 3
- 3
EditorialModel/test/me.json View File

@@ -12,10 +12,10 @@
12 12
     "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"0", "internal":"", "icon":"0"
13 13
   },
14 14
   "5" : {
15
-    "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "selected_fields":[7]
15
+    "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "fields_list":[7]
16 16
   },
17 17
   "6" : {
18
-    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "selected_fields":[10]
18
+    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "fields_list":[10]
19 19
   },
20 20
   "7" : {
21 21
     "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
@@ -39,7 +39,7 @@
39 39
     "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help_text":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"
40 40
   },
41 41
   "14" : {
42
-    "component":"EmType", "name":"rubrique", "string":"{\"fre\":\"Rubrique\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13", "icon":"0", "sortcolumn":"rank", "subordinates":[["parent",5], ["parent",14]]
42
+    "component":"EmType", "name":"rubrique", "string":"{\"fre\":\"Rubrique\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13", "icon":"0", "sortcolumn":"rank", "subordinates_list":{"parent":[5,14]}
43 43
   },
44 44
   "15" : {
45 45
     "component":"EmFieldGroup", "name":"info", "string":"{\"fre\":\"Info\"}", "help_text":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"13"

+ 16
- 15
EditorialModel/types.py View File

@@ -25,20 +25,22 @@ class EmType(EmComponent):
25 25
     ## Instanciate a new EmType
26 26
     # @todo define and check types for icon and sortcolumn
27 27
     # @todo better check self.subordinates
28
-    def __init__(self, model, uid, name, class_id, selected_fields = [], subordinates = [], icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
28
+    def __init__(self, model, uid, name, class_id, fields_list = [], subordinates_list = {}, icon = '0', sortcolumn = 'rank', string = None, help_text = None, date_update = None, date_create = None, rank = None):
29 29
         self.class_id = class_id
30 30
         self.check_type('class_id', int)
31
-        self.selected_fields = selected_fields
32
-        self.check_type('selected_fields', list)
33
-        for l_uid in self.selected_fields:
31
+        self.fields_list = fields_list
32
+        self.check_type('fields_list', list)
33
+        for l_uid in self.fields_list:
34 34
             if not isinstance(l_uid, int):
35
-                raise AttributeError("Excepted selected_fields to be a list of integers, but found a +"+str(type(l_uid))+" in it")
35
+                raise AttributeError("Excepted fields_list to be a list of integers, but found a +"+str(type(l_uid))+" in it")
36 36
 
37
-        self.subordinates = subordinates
38
-        self.check_type('subordinates', list)
39
-        for l_uid in self.subordinates:
40
-            if not isinstance(l_uid[0], str) or not isinstance(l_uid[1], int):
41
-                raise AttributeError("Excepted selected_fields to be a list of nature,int !")
37
+        self.subordinates_list = subordinates_list
38
+        print(subordinates_list)
39
+        self.check_type('subordinates_list', dict)
40
+        for nature, uids in self.subordinates_list.items():
41
+            for uid in uids:
42
+                if not isinstance(uid, int):
43
+                    raise AttributeError("Excepted subordinates of nature %s to be a list int !" % nature)
42 44
 
43 45
         self.icon = icon
44 46
         self.sortcolumn = sortcolumn
@@ -83,8 +85,7 @@ class EmType(EmComponent):
83 85
     # @todo Check if the type is not linked by any EmClass
84 86
     # @todo Check if there is no other ''non-deletion'' conditions
85 87
     def delete(self):
86
-        subs = self.subordinates()
87
-        if sum([len(subs[subnat]) for subnat in subs]) > 0:
88
+        if sum(self.subordinates_list) > 0:
88 89
             return False
89 90
         #Delete all relation with superiors
90 91
         for nature, sups in self.superiors().items():
@@ -103,9 +104,9 @@ class EmType(EmComponent):
103 104
 
104 105
     ## Return selected optional field
105 106
     # @return A list of EmField instance
106
-    #def selected_fields(self):
107
-        #selected = [self.model.component(field_id) for field_id in self._fields['selected_fields']]
108
-        #return selected
107
+    def selected_fields(self):
108
+        selected = [self.model.component(field_id) for field_id in self.fields_list]
109
+        return selected
109 110
 
110 111
     ## Return the list of associated fields
111 112
     # @return A list of EmField instance

Loading…
Cancel
Save