Browse Source

Add 2 properties for LeRel2Type dynamically generated child classes

The two new properties are :
 - superior_cls stores a LeObject child class
 - subordinate_cls stores a LeObject child class
Yann Weber 9 years ago
parent
commit
3fbe9b69d5
1 changed files with 5 additions and 33 deletions
  1. 5
    33
      leapi/lefactory.py

+ 5
- 33
leapi/lefactory.py View File

@@ -92,10 +92,14 @@ class LeFactory(object):
92 92
             rel_code = """
93 93
 class {classname}(LeRel2Type):
94 94
     _rel_attr_fieldtypes = {attr_dict}
95
+    superior_cls = {supcls}
96
+    subordinate_cls = {subcls}
95 97
 
96 98
 """.format(
97 99
     classname = cls_name,
98
-    attr_dict = "{" + (','.join(['\n    %s: %s' % (repr(f), v) for f,v in attr_l.items()])) + "\n}"
100
+    attr_dict = "{" + (','.join(['\n    %s: %s' % (repr(f), v) for f,v in attr_l.items()])) + "\n}",
101
+    supcls = self.name2classname(src.name),
102
+    subcls = self.name2classname(related.name),
99 103
 )
100 104
             res_code += rel_code
101 105
         return res_code
@@ -198,27 +202,6 @@ import %s
198 202
         
199 203
         #Building the fieldtypes dict of LeObject
200 204
         (leobj_uid_fieldtype, leobj_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.common_fields)
201
-        """
202
-        leobj_fieldtypes = list()
203
-        leobj_uid_fieldtype = None
204
-        for fname, ftargs in EditorialModel.classtypes.common_fields.items():
205
-            ftargs = copy.copy(ftargs)
206
-            fieldtype = ftargs['fieldtype']
207
-            self.needed_fieldtypes |= set([fieldtype])
208
-            del(ftargs['fieldtype'])
209
-
210
-            constructor = '{ftname}.EmFieldType(**{ftargs})'.format(
211
-                ftname = GenericFieldType.module_name(fieldtype),
212
-                ftargs = ftargs,
213
-            )
214
-            if fieldtype == 'pk':
215
-                #
216
-                #       WARNING multiple PK not supported
217
-                #
218
-                leobj_uid_fieldtype = "{ %s: %s }"%(repr(fname),constructor)
219
-            else:
220
-                leobj_fieldtypes.append( '%s: %s'%(repr(fname), constructor) )
221
-        """
222 205
         #Building the fieldtypes dict for LeRelation
223 206
         (lerel_uid_fieldtype, lerel_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.relations_common_fields)
224 207
         # Fetching superior and subordinate fieldname for LeRelation
@@ -230,17 +213,6 @@ import %s
230 213
                     lesup = fname
231 214
                 else:
232 215
                     lesub = fname
233
-        """
234
-        lerel_fieldtypes = list()
235
-        lerel_uid_fieldtype = None
236
-        for fname, ftargs in EditorialModel.classtypes.relations_common_fields.items():
237
-            ftargs = copy.copy(ftargs)
238
-            fieldtype = ftargs['fieldtype']
239
-            self.needed_fieldtypes |= set([fieldtype])
240
-            del(ftargs['fieldtype'])
241
-
242
-            constructor
243
-        """ 
244 216
 
245 217
         result += """
246 218
 ## @brief _LeCrud concret class

Loading…
Cancel
Save