瀏覽代碼

Begin to fix back_reference update

Yann Weber 7 年之前
父節點
當前提交
aa1ccd4a8d
共有 2 個檔案被更改,包括 6 行新增5 行删除
  1. 2
    1
      lodel/leapi/leobject.py
  2. 4
    4
      lodel/plugins/mongodb_datasource/datasource.py

+ 2
- 1
lodel/leapi/leobject.py 查看文件

@@ -17,6 +17,7 @@ LodelContext.expose_modules(globals(), {
17 17
         'LeApiQueryErrors'],
18 18
     'lodel.plugin.exceptions': ['PluginError', 'PluginTypeError',
19 19
         'LodelScriptError', 'DatasourcePluginError'],
20
+    'lodel.exceptions': ['LodelFatalError'],
20 21
     'lodel.plugin.hooks': ['LodelHook'],
21 22
     'lodel.plugin': ['Plugin', 'DatasourcePlugin'],
22 23
     'lodel.leapi.datahandlers.base_classes': ['DatasConstructor', 'Reference']})
@@ -166,7 +167,7 @@ class LeObject(object):
166 167
     def reference_handlers(cls, with_backref = True):
167 168
         return {    fname: fdh 
168 169
                     for fname, fdh in cls.fields(True).items()
169
-                    if issubclass(fdh.__class__, Reference) and \
170
+                    if fdh.is_reference() and \
170 171
                         (not with_backref or fdh.back_reference is not None)}
171 172
     
172 173
     ##@brief Return a LeObject child class from a name

+ 4
- 4
lodel/plugins/mongodb_datasource/datasource.py 查看文件

@@ -303,7 +303,7 @@ abstract, preparing reccursiv calls" % (target, filters, relational_filters))
303 303
             old_datas_l = self.__collection(target).find(
304 304
                 mongo_filters)
305 305
             old_datas_l = list(old_datas_l)
306
-            
306
+        
307 307
         uidname = target.uid_fieldname()[0] #MULTIPLE UID BROKEN HERE
308 308
         for old_datas in old_datas_l:
309 309
             self.__update_backref(
@@ -366,7 +366,7 @@ abstract, preparing reccursiv calls" % (target, filters, relational_filters))
366 366
                 continue
367 367
             bref_cls = fdh.back_reference[0]
368 368
             bref_fname = fdh.back_reference[1]
369
-            if issubclass(fdh.__class__, MultipleRef):
369
+            if not fdh.is_singlereference():
370 370
                 #fdh is a multiple ref. So the update preparation will be
371 371
                 #divided into two loops :
372 372
                 #- one loop for deleting old datas
@@ -479,7 +479,7 @@ abstract, preparing reccursiv calls" % (target, filters, relational_filters))
479 479
         newdd = 'new' in values
480 480
         if bref_val is None:
481 481
             bref_val = bref_dh.empty()
482
-        if issubclass(bref_dh.__class__, MultipleRef):
482
+        if not bref_dh.is_singlereference():
483 483
             if oldd and newdd:
484 484
                 if tuid not in bref_val:
485 485
                     raise MongoDbConsistencyError("The value we want to \
@@ -546,7 +546,7 @@ value : in %s field %s" % (bref_leo,fname))
546 546
             raise MongoDbConsistencyError("Unable to get the object we make \
547 547
 reference to : %s with uid = %s" % (bref_cls, repr(uidv)))
548 548
         bref_dh = bref_leo.data_handler(bref_fname)
549
-        if not isinstance(bref_dh, Reference):
549
+        if not bref_dh.is_reference():
550 550
             raise LodelFatalError("Found a back reference field that \
551 551
 is not a reference : '%s' field '%s'" % (bref_leo, bref_fname))
552 552
         bref_val = bref_leo.data(bref_fname)

Loading…
取消
儲存