Browse Source

EmType : implement .fields()

comment selected_fields because it clashes with ._fields[]
 => we have to rethink of ._fields[] and fieldtypes
ArnAud 9 years ago
parent
commit
ee9104fd57
3 changed files with 10 additions and 13 deletions
  1. 2
    2
      EditorialModel/fieldgroups.py
  2. 2
    2
      EditorialModel/test/me.json
  3. 6
    9
      EditorialModel/types.py

+ 2
- 2
EditorialModel/fieldgroups.py View File

37
             em_type = self.model.component(type_id)
37
             em_type = self.model.component(type_id)
38
             fields = []
38
             fields = []
39
             for field in self.model.components(EmField):
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
                     continue
41
                     continue
42
                 # don't include relational field if parent should not be included
42
                 # don't include relational field if parent should not be included
43
                 if field.rel_field_id:
43
                 if field.rel_field_id:
44
                     parent = self.model.component(field.rel_field_id)
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
                         continue
46
                         continue
47
                 fields.append(field)
47
                 fields.append(field)
48
 
48
 

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

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"
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
   "5" : {
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
   "6" : {
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
   "7" : {
20
   "7" : {
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"
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 View File

34
 
34
 
35
     def __init__(self, data, model):
35
     def __init__(self, data, model):
36
         super(EmType, self).__init__(data, model)
36
         super(EmType, self).__init__(data, model)
37
-        for link in ['fields', 'subordinates']:
37
+        for link in ['selected_fields', 'subordinates']:
38
             if link in data:
38
             if link in data:
39
                 self._fields[link] = data[link]
39
                 self._fields[link] = data[link]
40
             else:
40
             else:
89
 
89
 
90
     ## Return selected optional field
90
     ## Return selected optional field
91
     # @return A list of EmField instance
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
     ## Return the list of associated fields
96
     ## Return the list of associated fields
97
     # @return A list of EmField instance
97
     # @return A list of EmField instance
98
     def fields(self):
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
     ## Select_field (Function)
102
     ## Select_field (Function)
106
     #
103
     #

Loading…
Cancel
Save