Sfoglia il codice sorgente

lecrud: get() flag instanciate to choose to get raw data or objects

ArnAud 9 anni fa
parent
commit
53663603fa
2 ha cambiato i file con 10 aggiunte e 8 eliminazioni
  1. 7
    6
      DataSource/MySQL/leapidatasource.py
  2. 3
    2
      leapi/lecrud.py

+ 7
- 6
DataSource/MySQL/leapidatasource.py Vedi File

@@ -43,7 +43,7 @@ class LeDataSourceSQL(DummyDatasource):
43 43
     # @todo for speed get rid of all_to_dicts
44 44
     # @todo filters: all use cases are not implemented
45 45
     # @todo group: mosql does not permit direction in group_by clause, it should, so for now we don't use direction in group clause
46
-    def select(self, target_cls, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=None):
46
+    def select(self, target_cls, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=None, instanciate=True):
47 47
 
48 48
         joins = []
49 49
         # it is a LeObject, query only on main table
@@ -119,8 +119,9 @@ class LeDataSourceSQL(DummyDatasource):
119 119
         #print(results)
120 120
 
121 121
         # instanciate each row to editorial components
122
-        results = [target_cls.object_from_data(datas) for datas in results]
123
-        #print('results', results)
122
+        if instanciate:
123
+            results = [target_cls.object_from_data(datas) for datas in results]
124
+            #print('results', results)
124 125
 
125 126
         return results
126 127
 
@@ -167,7 +168,7 @@ class LeDataSourceSQL(DummyDatasource):
167 168
         return result
168 169
 
169 170
     ## @brief update an existing lodel editorial component
170
-    # @param target_cls LeCrud(class) : The component class concerned by the update (a LeCrud child class (not instance !) )
171
+    # @param target_cls LeCrud(class) : Instance of the object concerned by the update
171 172
     # @param filters list : List of filters (see @ref leobject_filters)
172 173
     # @param rel_filters list : List of relationnal filters (see @ref leobject_filters)
173 174
     # @param **datas : Datas in kwargs
@@ -191,7 +192,7 @@ class LeDataSourceSQL(DummyDatasource):
191 192
 
192 193
             class_table = utils.r2t_table_name(target_cls._superior_cls.__name__, target_cls._subordinate_cls.__name__)
193 194
         else:
194
-            raise AttributeError("'%s' is not a LeType or a LeRelation, it is not possible to insert it" % target_cls)
195
+            raise AttributeError("'%s' is not a LeType nor a LeRelation, it's impossible to update it" % target_cls)
195 196
 
196 197
         for main_column_name in main_fields:
197 198
             if main_column_name in datas:
@@ -246,7 +247,7 @@ class LeDataSourceSQL(DummyDatasource):
246 247
             class_table = utils.r2t_table_name(superior_class.__name__, datas['subordinate'].__class__.__name__)
247 248
             fk_name = superior_class.name2class('LeRelation').uidname()
248 249
         else:
249
-            raise AttributeError("'%s' is not a LeType or a LeRelation, it is not possible to insert it" % target_cls)
250
+            raise AttributeError("'%s' is not a LeType nor a LeRelation, it's impossible to insert it" % target_cls)
250 251
 
251 252
         # extract main table datas from datas
252 253
         for main_column_name in main_fields:

+ 3
- 2
leapi/lecrud.py Vedi File

@@ -356,7 +356,7 @@ class _LeCrud(object):
356 356
     # @return A list of lodel editorial components instance
357 357
     # @todo think about LeObject and LeClass instanciation (partial instanciation, etc)
358 358
     @classmethod
359
-    def get(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0):
359
+    def get(cls, query_filters, field_list=None, order=None, group=None, limit=None, offset=0, instanciate=True):
360 360
         if field_list is None or len(field_list) == 0:
361 361
             #default field_list
362 362
             field_list = cls.fieldlist()
@@ -395,7 +395,8 @@ class _LeCrud(object):
395 395
                                             order=order,
396 396
                                             group=group,
397 397
                                             limit=limit,
398
-                                            offset=offset
398
+                                            offset=offset,
399
+                                            instanciate=instanciate
399 400
                                         )
400 401
 
401 402
         return results

Loading…
Annulla
Salva