浏览代码

EmType : implement .fields()

comment selected_fields because it clashes with ._fields[]
 => we have to rethink of ._fields[] and fieldtypes
ArnAud 9 年前
父节点
当前提交
ee9104fd57
共有 3 个文件被更改,包括 10 次插入13 次删除
  1. 2
    2
      EditorialModel/fieldgroups.py
  2. 2
    2
      EditorialModel/test/me.json
  3. 6
    9
      EditorialModel/types.py

+ 2
- 2
EditorialModel/fieldgroups.py 查看文件

@@ -37,12 +37,12 @@ class EmFieldGroup(EmComponent):
37 37
             em_type = self.model.component(type_id)
38 38
             fields = []
39 39
             for field in self.model.components(EmField):
40
-                if field.fieldgroup_id != self.uid or (field.optional and field.uid not in em_type._fields['fields']):
40
+                if field.fieldgroup_id != self.uid or (field.optional and field.uid not in em_type._fields['selected_fields']):
41 41
                     continue
42 42
                 # don't include relational field if parent should not be included
43 43
                 if field.rel_field_id:
44 44
                     parent = self.model.component(field.rel_field_id)
45
-                    if parent.optional and parent.uid not in em_type._fields['fields']:
45
+                    if parent.optional and parent.uid not in em_type._fields['selected_fields']:
46 46
                         continue
47 47
                 fields.append(field)
48 48
 

+ 2
- 2
EditorialModel/test/me.json 查看文件

@@ -12,10 +12,10 @@
12 12
     "component":"EmField", "name":"titre", "string":"{\"fre\":\"Titre\"}", "help":"{}", "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":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "fields":[7]
15
+    "component":"EmType", "name":"article", "string":"{\"fre\":\"Article\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"1", "icon":"0", "sortcolumn":"rank", "selected_fields":[7]
16 16
   },
17 17
   "6" : {
18
-    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "fields":[10]
18
+    "component":"EmType", "name":"personne", "string":"{\"fre\":\"Personne\"}", "help":"{}", "rank":"1", "date_update":"", "date_create":"", "class_id":"2", "icon":"0", "sortcolumn":"rank", "selected_fields":[10]
19 19
   },
20 20
   "7" : {
21 21
     "component":"EmField", "name":"soustitre", "string":"{\"fre\":\"Sous-titre\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"3", "rel_to_type_id":"", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"

+ 6
- 9
EditorialModel/types.py 查看文件

@@ -34,7 +34,7 @@ class EmType(EmComponent):
34 34
 
35 35
     def __init__(self, data, model):
36 36
         super(EmType, self).__init__(data, model)
37
-        for link in ['fields', 'subordinates']:
37
+        for link in ['selected_fields', 'subordinates']:
38 38
             if link in data:
39 39
                 self._fields[link] = data[link]
40 40
             else:
@@ -89,18 +89,15 @@ class EmType(EmComponent):
89 89
 
90 90
     ## Return selected optional field
91 91
     # @return A list of EmField instance
92
-    def selected_fields(self):
93
-        selected = [self.model.component(field_id) for field_id in self._fields['fields']]
94
-        return selected
92
+    #def selected_fields(self):
93
+        #selected = [self.model.component(field_id) for field_id in self._fields['selected_fields']]
94
+        #return selected
95 95
 
96 96
     ## Return the list of associated fields
97 97
     # @return A list of EmField instance
98 98
     def fields(self):
99
-        result = list()
100
-        for field in self.all_fields():
101
-            if not field.optional:
102
-                result.append(field)
103
-        return result + self.selected_fields()
99
+        fields = [field for fieldgroup in self.fieldgroups() for field in fieldgroup.fields(self.uid)]
100
+        return fields
104 101
 
105 102
     ## Select_field (Function)
106 103
     #

正在加载...
取消
保存