Browse Source

EmFieldgroups: fields(self, type_id=0) can now filter fields for EmType request

ArnAud 9 years ago
parent
commit
f72799af24
2 changed files with 20 additions and 3 deletions
  1. 19
    2
      EditorialModel/fieldgroups.py
  2. 1
    1
      EditorialModel/test/me.json

+ 19
- 2
EditorialModel/fieldgroups.py View File

@@ -27,10 +27,27 @@ class EmFieldGroup(EmComponent):
27 27
         return self.model.delete_component(self.uid)
28 28
 
29 29
     ## Get the list of associated fields
30
+    # if type_id, the fields will be filtered to represent selected fields of this EmType
30 31
     # @return A list of EmField instance
31
-    def fields(self):
32
-        fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
32
+    def fields(self, type_id=0):
33
+        if not type_id:
34
+            fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
35
+        else:
36
+            # for an EmType, fileds have to be filtered
37
+            em_type = self.model.component(type_id)
38
+            fields = []
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']):
41
+                    continue
42
+                # don't include relational field if parent should not be included
43
+                if 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']:
46
+                        continue
47
+                fields.append(field)
48
+
33 49
         return fields
34 50
 
51
+
35 52
 class NotEmptyError(Exception):
36 53
     pass

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

@@ -33,7 +33,7 @@
33 33
     "component":"EmField", "name":"auteur", "string":"{\"fre\":\"Auteur\"}", "help":"{}", "rank":"3", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"6", "rel_field_id":"", "optional":"1", "internal":"", "icon":"0"
34 34
   },
35 35
   "12" : {
36
-    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help":"{}", "rank":"4", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"", "rel_field_id":"11", "optional":"1", "internal":"", "icon":"0"
36
+    "component":"EmField", "name":"adresse", "string":"{\"fre\":\"Adresse\"}", "help":"{}", "rank":"4", "date_update":"", "date_create":"", "fieldtype":"", "fieldgroup_id":"17", "rel_to_type_id":"", "rel_field_id":"11", "optional":"0", "internal":"", "icon":"0"
37 37
   },
38 38
   "13" : {
39 39
     "component":"EmClass", "name":"publication", "string":"{\"fre\":\"Publication\"}", "help":"{}", "rank":"2", "date_update":"", "date_create":"", "classtype":"entity", "icon":"0", "sortcolumn":"rank"

Loading…
Cancel
Save