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

+ 7
- 2
EditorialModel/fieldgroups.py View File

45
 
45
 
46
     ## Get the list of associated fields
46
     ## Get the list of associated fields
47
     # if type_id, the fields will be filtered to represent selected fields of this EmType
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
     # @return A list of EmField instance
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
             fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
53
             fields = [field for field in self.model.components(EmField) if field.fieldgroup_id == self.uid]
52
         else:
54
         else:
53
             # for an EmType, fields have to be filtered
55
             # for an EmType, fields have to be filtered
62
                     if parent.optional and parent.uid not in em_type.fields_list:
64
                     if parent.optional and parent.uid not in em_type.fields_list:
63
                         continue
65
                         continue
64
                 fields.append(field)
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
         return fields
71
         return fields
67
 
72
 

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

179
                 res.append(field.uid)
179
                 res.append(field.uid)
180
             self.assertEqual(set(res), set(expected1))
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
     def test_empty_fields(self):
188
     def test_empty_fields(self):
183
         """ Testing fields method on an empty fieldgroup """
189
         """ Testing fields method on an empty fieldgroup """
184
         fieldgroup = self.fg3
190
         fieldgroup = self.fg3

+ 3
- 1
EditorialModel/types.py View File

101
 
101
 
102
     ## Return the list of associated fields
102
     ## Return the list of associated fields
103
     # @return A list of EmField instance
103
     # @return A list of EmField instance
104
-    def fields(self):
104
+    def fields(self, relational = False):
105
         fields = [field for fieldgroup in self.fieldgroups() for field in fieldgroup.fields(self.uid)]
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
         return fields
108
         return fields
107
 
109
 
108
     ## Select_field (Function)
110
     ## Select_field (Function)

+ 10
- 6
leobject/lefactory.py View File

65
     def emclass_pycode(model, emclass):
65
     def emclass_pycode(model, emclass):
66
         cls_fields = dict()
66
         cls_fields = dict()
67
         cls_linked_types = list()
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
             cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
74
             cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
70
             fti = field.fieldtype_instance()
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
         cls_fieldgroup = dict()
78
         cls_fieldgroup = dict()
75
         for fieldgroup in emclass.fieldgroups():
79
         for fieldgroup in emclass.fieldgroups():
76
             cls_fieldgroup[fieldgroup.name] = list()
80
             cls_fieldgroup[fieldgroup.name] = list()
77
-            for field in fieldgroup.fields():
81
+            for field in fieldgroup.fields(relational = False):
78
                 cls_fieldgroup[fieldgroup.name].append(field.name)
82
                 cls_fieldgroup[fieldgroup.name].append(field.name)
79
 
83
 
80
         return """
84
         return """
97
     def emtype_pycode(model, emtype):
101
     def emtype_pycode(model, emtype):
98
         type_fields = list()
102
         type_fields = list()
99
         type_superiors = list()
103
         type_superiors = list()
100
-        for field in emtype.fields():
104
+        for field in emtype.fields(relational=False):
101
             type_fields.append(field.name)
105
             type_fields.append(field.name)
102
 
106
 
103
         for nat, sup_l in emtype.superiors().items():
107
         for nat, sup_l in emtype.superiors().items():

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

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

Loading…
Cancel
Save