Browse Source

New constants in EditorialModel.classtypes

Yann Weber 9 years ago
parent
commit
173564b7ee
5 changed files with 36 additions and 34 deletions
  1. 14
    6
      EditorialModel/classtypes.py
  2. 4
    5
      leapi/lecrud.py
  3. 7
    23
      leapi/lefactory.py
  4. 5
    0
      leapi/leobject.py
  5. 6
    0
      leapi/lerelation.py

+ 14
- 6
EditorialModel/classtypes.py View File

@@ -1,17 +1,25 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+object_uid = 'lodel_id'
4
+object_em_class_id = 'class_id'
5
+object_em_type_id = 'type_id'
6
+
7
+relation_uid = 'id_relation'
8
+relation_superior = 'superior'
9
+relation_subordinate = 'subordinate'
10
+
3 11
 
4 12
 common_fields = {
5
-    'lodel_id': {
13
+    object_uid: {
6 14
         'fieldtype': 'pk',
7 15
         'internal': 'autosql',
8 16
     },
9
-    'class_id': {
17
+    object_em_class_id : {
10 18
         'fieldtype': 'emuid',
11 19
         'is_id_class': True,
12 20
         'internal': 'automatic',
13 21
     },
14
-    'type_id': {
22
+    object_em_type_id : {
15 23
         'fieldtype': 'emuid',
16 24
         'is_id_class': False,
17 25
         'internal': 'automatic',
@@ -36,7 +44,7 @@ common_fields = {
36 44
 }
37 45
 
38 46
 relations_common_fields = {
39
-    'id_relation': {
47
+    relation_uid: {
40 48
         'fieldtype': 'pk',
41 49
         'internal': 'autosql',
42 50
     },
@@ -51,11 +59,11 @@ relations_common_fields = {
51 59
         'fieldtype': 'rank',
52 60
         'internal': 'automatic',
53 61
     },
54
-    'superior': {
62
+    relation_superior : {
55 63
         'fieldtype': 'leo',
56 64
         'superior': True,
57 65
     },
58
-    'subordinate': {
66
+    relation_subordinate: {
59 67
         'fieldtype': 'leo',
60 68
         'superior': False,
61 69
     }

+ 4
- 5
leapi/lecrud.py View File

@@ -4,6 +4,7 @@
4 4
 # @brief This package contains the abstract class representing Lodel Editorial components
5 5
 #
6 6
 
7
+import copy
7 8
 import warnings
8 9
 import importlib
9 10
 import re
@@ -151,9 +152,7 @@ class _LeCrud(object):
151 152
     # @todo test for abstract method !!!
152 153
     @classmethod
153 154
     def uidname(cls):
154
-        if cls._uid_fieldtype is None or len(cls._uid_fieldtype) == 0:
155
-            raise NotImplementedError("Abstract method uid_name for %s!"%cls.__name__)
156
-        return list(cls._uid_fieldtype.keys())[0]
155
+        raise NotImplementedError("Abstract method uid_name for %s!"%cls.__name__)
157 156
     
158 157
     ## @return maybe Bool: True if cls implements LeType
159 158
     # @param cls Class: a Class or instanciated object
@@ -461,10 +460,10 @@ class _LeCrud(object):
461 460
     # @todo Decide wether or not the datas are modifed inplace or returned in a new dict (second solution for the moment)
462 461
     @classmethod
463 462
     def _construct_datas(cls, datas):
464
-        res_datas = dict()
463
+        res_datas = copy.copy(datas)
465 464
         for fname, ftype in cls.fieldtypes().items():
466 465
             if not ftype.is_internal() or ftype.internal != 'autosql':
467
-                res_datas[fname] = ftype.construct_data(cls, fname, datas)
466
+                res_datas[fname] = ftype.construct_data(cls, fname, res_datas)
468 467
         return res_datas
469 468
     ## @brief Check datas consistency
470 469

+ 7
- 23
leapi/lefactory.py View File

@@ -5,6 +5,7 @@ import copy
5 5
 import os.path
6 6
 
7 7
 import EditorialModel
8
+from EditorialModel import classtypes
8 9
 from EditorialModel.model import Model
9 10
 from EditorialModel.fieldtypes.generic import GenericFieldType
10 11
 from leapi.lecrud import _LeCrud
@@ -196,25 +197,6 @@ import %s
196 197
         (leobj_uid_fieldtype, leobj_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.common_fields)
197 198
         #Building the fieldtypes dict for LeRelation
198 199
         (lerel_uid_fieldtype, lerel_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.relations_common_fields)
199
-        # Fetching superior and subordinate fieldname for LeRelation
200
-        lesup = None
201
-        lesub = None
202
-        for fname, finfo in EditorialModel.classtypes.relations_common_fields.items():
203
-            if finfo['fieldtype'] == 'leo':
204
-                if finfo['superior']:
205
-                    lesup = fname
206
-                else:
207
-                    lesub = fname
208
-        # Fetch class_id and type_id fieldnames for LeObject
209
-        class_id = None
210
-        type_id = None
211
-        for fname, finfo in EditorialModel.classtypes.common_fields.items():
212
-            if finfo['fieldtype'] == 'emuid':
213
-                if finfo['is_id_class']:
214
-                    class_id = fname
215
-                else:
216
-                    type_id = fname
217
-        # TEST IF SOME OF THE ARE NONE !!!
218 200
 
219 201
         result += """
220 202
 ## @brief _LeCrud concret class
@@ -236,7 +218,9 @@ class LeObject(LeCrud, leapi.leobject._LeObject):
236 218
 class LeRelation(LeCrud, leapi.lerelation._LeRelation):
237 219
     _uid_fieldtype = {lerel_uid_fieldtype}
238 220
     _rel_fieldtypes = {lerel_fieldtypes}
221
+    ## WARNING !!!! OBSOLETE ! DON'T USE IT
239 222
     _superior_field_name = {lesup_name}
223
+    ## WARNING !!!! OBSOLETE ! DON'T USE IT
240 224
     _subordinate_field_name = {lesub_name}
241 225
 
242 226
 class LeHierarch(LeRelation, leapi.lerelation._LeHierarch):
@@ -258,10 +242,10 @@ class LeType(LeClass, _LeType):
258 242
             leo_fieldtypes = '{\n\t' + (',\n\t'.join(leobj_fieldtypes))+ '\n\t}',
259 243
             lerel_fieldtypes = '{\n\t' + (',\n\t'.join(lerel_fieldtypes))+ '\n\t}',
260 244
             lerel_uid_fieldtype = lerel_uid_fieldtype,
261
-            lesup_name = repr(lesup),
262
-            lesub_name = repr(lesub),
263
-            class_id = repr(class_id),
264
-            type_id = repr(type_id),
245
+            lesup_name = repr(classtypes.relation_superior),
246
+            lesub_name = repr(classtypes.relation_subordinate),
247
+            class_id = repr(classtypes.object_em_class_id),
248
+            type_id = repr(classtypes.object_em_type_id),
265 249
         )
266 250
 
267 251
         emclass_l = model.components(EditorialModel.classes.EmClass)

+ 5
- 0
leapi/leobject.py View File

@@ -59,6 +59,11 @@ class _LeObject(_LeCrud):
59 59
     def __repr__(self):
60 60
         return self.__str__()
61 61
     
62
+    ## @brief Returns the name of the uid field
63
+    @classmethod
64
+    def uidname(cls):
65
+        return EditorialModel.classtypes.object_uid
66
+
62 67
     ## @brief Given a ME uid return the corresponding LeClass or LeType class
63 68
     # @return a LeType or LeClass child class
64 69
     # @throw KeyError if no corresponding child classes

+ 6
- 0
leapi/lerelation.py View File

@@ -33,6 +33,12 @@ class _LeRelation(lecrud._LeCrud):
33 33
         if isinstance(leo, leobject._LeObject):
34 34
             return (self._subordinate_field_name, '=', leo)
35 35
 
36
+    
37
+    ## @return The name of the uniq id field
38
+    @classmethod
39
+    def uidname(cls):
40
+        return EditorialModel.classtypes.relation_uid
41
+
36 42
     ## @return a dict with field name as key and fieldtype instance as value
37 43
     @classmethod
38 44
     def fieldtypes(cls):

Loading…
Cancel
Save