Browse Source

Bugfix on backreferences + updates of em_test

Yann Weber 8 years ago
parent
commit
a57899fb18
4 changed files with 9 additions and 12 deletions
  1. 2
    2
      em_test.py
  2. BIN
      examples/em_test.pickle
  3. 4
    9
      lodel/leapi/datahandlers/base_classes.py
  4. 3
    1
      lodel/leapi/leobject.py

+ 2
- 2
em_test.py View File

225
                         'fre': 'Textes liés',
225
                         'fre': 'Textes liés',
226
                     },
226
                     },
227
                     data_handler = 'list',
227
                     data_handler = 'list',
228
-                    back_reference = ('Text', 'lodel_id'),
228
+                    back_reference = ('Text', 'linked_persons'),
229
                     group = editorial_person_group,
229
                     group = editorial_person_group,
230
 )
230
 )
231
 
231
 
235
                     'fre': 'Personnes liées',
235
                     'fre': 'Personnes liées',
236
                 },
236
                 },
237
                 data_handler = 'list',
237
                 data_handler = 'list',
238
-                back_reference = ('Person', 'lodel_id'),
238
+                back_reference = ('Person', 'linked_texts'),
239
                 group = editorial_person_group,
239
                 group = editorial_person_group,
240
 )
240
 )
241
 
241
 

BIN
examples/em_test.pickle View File


+ 4
- 9
lodel/leapi/datahandlers/base_classes.py View File

199
         return self.__back_reference
199
         return self.__back_reference
200
 
200
 
201
     ## @brief Set the back reference for this field.
201
     ## @brief Set the back reference for this field.
202
-    # 
203
-    # This method is designed to be called from LeObject child classes
204
-    # at dyncode load. LeObject dynamic childs classes are the objects that are
205
-    # able to fetch python classes from name.
206
-    def _set_back_reference(self, back_reference = None):
207
-        
208
-        pass
202
+    def _set_back_reference(self, back_reference):
203
+        self.__back_reference = back_reference
209
         
204
         
210
 
205
 
211
     ## @brief Check value
206
     ## @brief Check value
248
 class MultipleRef(Reference):
243
 class MultipleRef(Reference):
249
     
244
     
250
     def __init__(self, allowed_classes = None, **kwargs):
245
     def __init__(self, allowed_classes = None, **kwargs):
251
-        super().__init__(allowed_classes = allowed_classes)
252
- 
246
+        super().__init__(allowed_classes = allowed_classes, **kwargs)
247
+
253
 
248
 

+ 3
- 1
lodel/leapi/leobject.py View File

165
     @classmethod
165
     @classmethod
166
     def _backref_init(cls):
166
     def _backref_init(cls):
167
         for fname,field in cls._fields.items():
167
         for fname,field in cls._fields.items():
168
+            #if field.is_reference():
169
+            #    print(fname, field.back_reference)
168
             if field.is_reference() and field.back_reference is not None:
170
             if field.is_reference() and field.back_reference is not None:
169
                 cls_name, field_name = field.back_reference
171
                 cls_name, field_name = field.back_reference
170
                 bref_leobject = cls.name2class(cls.name2objname(cls_name))
172
                 bref_leobject = cls.name2class(cls.name2objname(cls_name))
171
                 if field_name not in bref_leobject._fields:
173
                 if field_name not in bref_leobject._fields:
172
                     raise NameError("LeObject %s doesn't have a field named '%s'" % (cls_name, field_name))
174
                     raise NameError("LeObject %s doesn't have a field named '%s'" % (cls_name, field_name))
173
-                field.set_backreference(bref_leobject._fields[field_name])
175
+                field._set_back_reference(bref_leobject._fields[field_name])
174
 
176
 
175
     @classmethod
177
     @classmethod
176
     def is_abstract(cls):
178
     def is_abstract(cls):

Loading…
Cancel
Save