Bläddra i källkod

Bugfixes concerning UniqID and select on abtract LeObject child

Yann Weber 8 år sedan
förälder
incheckning
8e6e60f0f4
2 ändrade filer med 13 tillägg och 4 borttagningar
  1. 7
    1
      lodel/leapi/lefactory.py
  2. 6
    3
      plugins/mongodb_datasource/datasource.py

+ 7
- 1
lodel/leapi/lefactory.py Visa fil

@@ -145,12 +145,18 @@ class {clsname}({parents}):
145 145
 )
146 146
         res += em_cls_code
147 147
         # Dyncode fields bootstrap instructions
148
+        child_classes = model.get_class_childs(em_class.uid)
149
+        if len(child_classes) == 0:
150
+            child_classes = 'tuple()'
151
+        else:
152
+            child_classes = '(%s,)' % (', '.join(
153
+                [ LeObject.name2objname(emcls.uid) for emcls in child_classes]))
148 154
         bootstrap += """{classname}._set__fields({fields})
149 155
 {classname}._child_classes = {child_classes}
150 156
 """.format(
151 157
     classname = LeObject.name2objname(em_class.uid),
152 158
     fields = '{' + (', '.join(['\n\t%s: %s' % (repr(emfield.uid),data_handler_constructor(emfield)) for emfield in em_class.fields()])) + '}',
153
-    child_classes = '(' + (', '.join([ LeObject.name2objname(emcls.uid) for emcls in model.get_class_childs(em_class.uid)]))+ ')',
159
+    child_classes = child_classes,
154 160
 )
155 161
     bootstrap += "\n"
156 162
     return res, set(imports), bootstrap

+ 6
- 3
plugins/mongodb_datasource/datasource.py Visa fil

@@ -76,6 +76,8 @@ class MongoDbDatasource(object):
76 76
         tuid = target._uid[0] # Multiple UID broken here
77 77
         results = self.select(
78 78
             target, [tuid], [], order=[(tuid, 'DESC')], limit = 1)
79
+        if len(results) == 0: 
80
+            return 1
79 81
         return results[0][tuid]+1
80 82
 
81 83
     ##@brief returns a selection of documents from the datasource
@@ -96,9 +98,10 @@ class MongoDbDatasource(object):
96 98
         if target.is_abstract():
97 99
             target_childs = target.child_classes()
98 100
             for target_child in target_childs:
99
-                results.append(self.select(target=target_child, field_list=field_list, filters=filters,
100
-                                           rel_filters=rel_filters, order=order, group=group, limit=limit,
101
-                                           offset=offset))
101
+                results += self.select(
102
+                    target=target_child, field_list=field_list,
103
+                    filters=filters, rel_filters=rel_filters, order=order,
104
+                    group=group, limit=limit, offset=offset)
102 105
         else:
103 106
             # Default arg init
104 107
             filters = [] if filters is None else filters

Loading…
Avbryt
Spara