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,7 +225,7 @@ person.new_field(   'linked_texts',
225 225
                         'fre': 'Textes liés',
226 226
                     },
227 227
                     data_handler = 'list',
228
-                    back_reference = ('Text', 'lodel_id'),
228
+                    back_reference = ('Text', 'linked_persons'),
229 229
                     group = editorial_person_group,
230 230
 )
231 231
 
@@ -235,7 +235,7 @@ text.new_field( 'linked_persons',
235 235
                     'fre': 'Personnes liées',
236 236
                 },
237 237
                 data_handler = 'list',
238
-                back_reference = ('Person', 'lodel_id'),
238
+                back_reference = ('Person', 'linked_texts'),
239 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,13 +199,8 @@ class Reference(DataHandler):
199 199
         return self.__back_reference
200 200
 
201 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 206
     ## @brief Check value
@@ -248,6 +243,6 @@ class SingleRef(Reference):
248 243
 class MultipleRef(Reference):
249 244
     
250 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,12 +165,14 @@ class LeObject(object):
165 165
     @classmethod
166 166
     def _backref_init(cls):
167 167
         for fname,field in cls._fields.items():
168
+            #if field.is_reference():
169
+            #    print(fname, field.back_reference)
168 170
             if field.is_reference() and field.back_reference is not None:
169 171
                 cls_name, field_name = field.back_reference
170 172
                 bref_leobject = cls.name2class(cls.name2objname(cls_name))
171 173
                 if field_name not in bref_leobject._fields:
172 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 177
     @classmethod
176 178
     def is_abstract(cls):

Loading…
Cancel
Save