Browse Source

Removing rel2type fields and rel2type attributes fields from LeClass and LeType fields lists

Yann Weber 9 years ago
parent
commit
7b0df11496

+ 2
- 2
EditorialModel/classes.py View File

@@ -81,11 +81,11 @@ class EmClass(EmComponent):
81 81
 
82 82
     ## Retrieve list of fields
83 83
     # @return fields [EmField]:
84
-    def fields(self):
84
+    def fields(self, relational = True):
85 85
         fieldgroups = self.fieldgroups()
86 86
         fields = []
87 87
         for fieldgroup in fieldgroups:
88
-            fields += fieldgroup.fields()
88
+            fields += fieldgroup.fields(relational=relational)
89 89
         return fields
90 90
 
91 91
     ## Retrieve list of type of this class

+ 7
- 2
EditorialModel/fieldgroups.py View File

@@ -45,9 +45,11 @@ class EmFieldGroup(EmComponent):
45 45
 
46 46
     ## Get the list of associated fields
47 47
     # if type_id, the fields will be filtered to represent selected fields of this EmType
48
+    # @param type_id int|None : if not None the fields will be filtered to represent selected fields of the EmType identified by this uid
49
+    # @param relational bool : If False don't returns the relational fields
48 50
     # @return A list of EmField instance
49
-    def fields(self, type_id=0):
50
-        if not type_id:
51
+    def fields(self, type_id=None, relational=True):
52
+        if type_id is None:
51 53
             fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
52 54
         else:
53 55
             # for an EmType, fields have to be filtered
@@ -62,6 +64,9 @@ class EmFieldGroup(EmComponent):
62 64
                     if parent.optional and parent.uid not in em_type.fields_list:
63 65
                         continue
64 66
                 fields.append(field)
67
+        
68
+        if not relational:
69
+            fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
65 70
 
66 71
         return fields
67 72
 

+ 6
- 0
EditorialModel/test/test_fieldgroups.py View File

@@ -179,6 +179,12 @@ class TestFields(FieldGroupTestCase):
179 179
                 res.append(field.uid)
180 180
             self.assertEqual(set(res), set(expected1))
181 181
 
182
+    def test_non_relational(self):
183
+        """ Check that relationnal=False returns only non relational fields """
184
+        for fgrp in [ self.fg1, self.fg2, self.fg3 ]:
185
+            for field in fgrp.fields(relational=False):
186
+                self.assertTrue(field.fieldtype != 'rel2type' and field.rel_field_id is None)
187
+
182 188
     def test_empty_fields(self):
183 189
         """ Testing fields method on an empty fieldgroup """
184 190
         fieldgroup = self.fg3

+ 3
- 1
EditorialModel/types.py View File

@@ -101,8 +101,10 @@ class EmType(EmComponent):
101 101
 
102 102
     ## Return the list of associated fields
103 103
     # @return A list of EmField instance
104
-    def fields(self):
104
+    def fields(self, relational = False):
105 105
         fields = [field for fieldgroup in self.fieldgroups() for field in fieldgroup.fields(self.uid)]
106
+        if not relational:
107
+            fields = [ f for f in fields if f.rel_field_id is None and f.fieldtype != 'rel2type' ]
106 108
         return fields
107 109
 
108 110
     ## Select_field (Function)

+ 10
- 6
leobject/lefactory.py View File

@@ -65,16 +65,20 @@ class LeFactory(object):
65 65
     def emclass_pycode(model, emclass):
66 66
         cls_fields = dict()
67 67
         cls_linked_types = list()
68
-        for field in emclass.fields():
68
+        #Populating linked_type attr
69
+        for rfield in [ f for f in emclass.fields() if f.fieldtype == 'rel2type']:
70
+            fti = rfield.fieldtype_instance()
71
+            cls_linked_types.append(LeFactory.name2classname(model.component(fti.rel_to_type_id).name))
72
+        # Populating fieldtype attr
73
+        for field in emclass.fields(relational = False):
69 74
             cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
70 75
             fti = field.fieldtype_instance()
71
-            if fti.name == 'rel2type':
72
-                #relationnal field/fieldtype
73
-                cls_linked_types.append(LeFactory.name2classname(model.component(fti.rel_to_type_id).name))
76
+        
77
+        # Populating fieldgroup attr
74 78
         cls_fieldgroup = dict()
75 79
         for fieldgroup in emclass.fieldgroups():
76 80
             cls_fieldgroup[fieldgroup.name] = list()
77
-            for field in fieldgroup.fields():
81
+            for field in fieldgroup.fields(relational = False):
78 82
                 cls_fieldgroup[fieldgroup.name].append(field.name)
79 83
 
80 84
         return """
@@ -97,7 +101,7 @@ class LeFactory(object):
97 101
     def emtype_pycode(model, emtype):
98 102
         type_fields = list()
99 103
         type_superiors = list()
100
-        for field in emtype.fields():
104
+        for field in emtype.fields(relational=False):
101 105
             type_fields.append(field.name)
102 106
 
103 107
         for nat, sup_l in emtype.superiors().items():

+ 3
- 3
leobject/test/test_lefactory.py View File

@@ -69,7 +69,7 @@ class TestLeFactory(TestCase):
69 69
             )
70 70
             for fgroup in emclass.fieldgroups():
71 71
                 self.assertEqual(
72
-                    set([ f.name for f in fgroup.fields()]),
72
+                    set([ f.name for f in fgroup.fields(relational=False)]),
73 73
                     set(leclass._fieldgroups[fgroup.name])
74 74
                 )
75 75
             
@@ -81,10 +81,10 @@ class TestLeFactory(TestCase):
81 81
 
82 82
             #Testing fieldtypes
83 83
             self.assertEqual(
84
-                set([ f.name for f in emclass.fields()]),
84
+                set([ f.name for f in emclass.fields(relational=False)]),
85 85
                 set(leclass._fieldtypes.keys())
86 86
             )
87
-            for field in emclass.fields():
87
+            for field in emclass.fields(relational=False):
88 88
                 self.assertEqual(
89 89
                     hash(field.fieldtype_instance()),
90 90
                     hash(leclass._fieldtypes[field.name])

Loading…
Cancel
Save