Browse Source

Fixing lequery execute -> __query process

- deleting most of **datas to replace it with a standart dict argument
- using filters in childs of LeFilteredQuery
Yann Weber 8 years ago
parent
commit
7e2a60e73e
1 changed files with 17 additions and 32 deletions
  1. 17
    32
      lodel/leapi/query.py

+ 17
- 32
lodel/leapi/query.py View File

@@ -484,9 +484,9 @@ class LeInsertQuery(LeQuery):
484 484
         super().__init__(target_class)
485 485
     
486 486
     ## @brief Implements an insert query operation, with only one insertion
487
-    # @param **datas : datas to be inserted
488
-    def __query(self, **datas):
489
-        nb_inserted = self._datasource.insert(self._target_class,**datas)
487
+    # @param new_datas : datas to be inserted
488
+    def __query(self, new_datas):
489
+        nb_inserted = self._datasource.insert(self._target_class,new_datas)
490 490
         if nb_inserted < 0:
491 491
             raise LeQueryError("Insertion error")
492 492
         return nb_inserted
@@ -502,8 +502,8 @@ class LeInsertQuery(LeQuery):
502 502
     """
503 503
 
504 504
     ## @brief Execute the insert query
505
-    def execute(self, **datas):
506
-        return super().execute(**datas)
505
+    def execute(self, new_datas):
506
+        return super().execute(new_datas)
507 507
         
508 508
 ##@brief A query to update datas for a given object
509 509
 class LeUpdateQuery(LeFilteredQuery):
@@ -515,34 +515,18 @@ class LeUpdateQuery(LeFilteredQuery):
515 515
         super().__init__(target_class, query_filter)
516 516
     
517 517
     ##@brief Implements an update query
518
-    # @param **datas : datas to update
519
-    # @returns the number of updated items
520
-    # @exception when the number of updated items is not as expected
521
-    def __query(self, **datas):
522
-        # select _uid corresponding to query_filter
523
-        l_uids=self._datasource.select( self._target_class,
524
-                                        list(self._target_class.getuid()),
525
-                                        query_filter,
526
-                                        None,
527
-                                        None,
528
-                                        None,
529
-                                        None,
530
-                                        0,
531
-                                        False)
532
-        # list of dict l_uids : _uid(s) of the objects to be updated,
533
-        # corresponding datas
534
-        nb_updated = self._datasource.update(   self._target_class,
535
-                                                l_uids,
536
-                                                **datas)
537
-        if nb_updated != len(l_uids):
538
-            msg = "Number of updated items: %d is not as expected: %d "
539
-            msg %= (nb_updated, len(l_uids))
540
-            raise LeQueryError(msg)
518
+    #@param filters list : see @ref LeFilteredQuery
519
+    #@param rel_filters list : see @ref LeFilteredQuery
520
+    #@param updated_datas dict : datas to update
521
+    #@returns the number of updated items
522
+    def __query(self, filters, rel_filters, updated_datas):
523
+        nb_updated = self._datasource.update(
524
+            self._target_class, filters, rel_filters, update_datas)
541 525
         return nb_updated
542 526
     
543 527
     ## @brief Execute the update query
544
-    def execute(self, **datas):
545
-        return super().execute(**datas)
528
+    def execute(self, updated_datas):
529
+        return super().execute(updated_datas)
546 530
 
547 531
 ##@brief A query to delete an object
548 532
 class LeDeleteQuery(LeFilteredQuery):
@@ -557,8 +541,9 @@ class LeDeleteQuery(LeFilteredQuery):
557 541
         return super().execute()
558 542
     
559 543
     ##@brief Implements delete query operations
560
-    # @returns the number of deleted items
561
-    # @exception when the number of deleted items is not as expected
544
+    #@param filters list : see @ref LeFilteredQuery
545
+    #@param rel_filters list : see @ref LeFilteredQuery
546
+    #@returns the number of deleted items
562 547
     def __query(self, filters, rel_filters):
563 548
         nb_deleted = datasource.delete(
564 549
             self._target_class, filters, rel_filters)

Loading…
Cancel
Save