Browse Source

Better comments + 79char limit on mongodb datasource

Yann Weber 8 years ago
parent
commit
8a32f1973a
1 changed files with 27 additions and 19 deletions
  1. 27
    19
      plugins/mongodb_datasource/datasource.py

+ 27
- 19
plugins/mongodb_datasource/datasource.py View File

@@ -89,7 +89,8 @@ class MongoDbDatasource(object):
89 89
     #@param field_list list
90 90
     #@param filters list : List of filters
91 91
     #@param rel_filters list : List of relational filters
92
-    #@param order list : List of column to order. ex: order = [('title', 'ASC'),]
92
+    #@param order list : List of column to order. ex: order = 
93
+    #[('title', 'ASC'),]
93 94
     #@param group list : List of tupple representing the column used as 
94 95
     #"group by" fields. ex: group = [('title', 'ASC'),]
95 96
     #@param limit int : Number of records to be returned
@@ -103,31 +104,36 @@ class MongoDbDatasource(object):
103 104
             results =  self.__act_on_abstract(target, filters,
104 105
                 relational_filters, self.select, field_list = field_list,
105 106
                 order = order, group = group, limit = limit)
106
-            sort_itemgetter_args = list()
107
-            sort_dir = None
108
-            for fname, csort_dir in order:
109
-                sort_itemgetter_args.append(fname)
110
-                if sort_dir is None:
111
-                    sort_dir = csort_dir
112
-                elif sort_dir != csort_dir:
113
-                    raise NotImplementedError("Multiple direction for ordering\
114
- is not implemented yet")
115
-            results = sorted(
116
-                results, key=operator.itemgetter(*sort_itemgetter_args),
117
-                reverse=False if sort_dir == 'ASC' else True)
107
+            #Here we may implement the group
108
+            #If sorted query we have to sort again
109
+            if order is not None:
110
+                sort_itemgetter_args = list()
111
+                sort_dir = None
112
+                for fname, csort_dir in order:
113
+                    sort_itemgetter_args.append(fname)
114
+                    if sort_dir is None:
115
+                        sort_dir = csort_dir
116
+                    elif sort_dir != csort_dir:
117
+                        raise NotImplementedError("Multiple direction for \
118
+ordering is not implemented yet")
119
+                results = sorted(
120
+                    results, key=operator.itemgetter(*sort_itemgetter_args),
121
+                    reverse=False if sort_dir == 'ASC' else True)
122
+            #If limit given apply limit again
118 123
             if limit is not None:
119 124
                 results = results[offset:offset+limit]
120 125
             return results
121
-                
122
-                
123 126
         # Default behavior
124
-        filters = [] if filters is None else filters
125
-        relational_filters = [] if relational_filters is None else relational_filters
127
+        if filters is None:
128
+            filters = list()
129
+        if relational_filters is None:
130
+            relational_filters = list()
126 131
 
127 132
         collection_name = object_collection_name(target)
128 133
         collection = self.database[collection_name]
129 134
 
130
-        query_filters = self.__process_filters(target, filters, relational_filters)
135
+        query_filters = self.__process_filters(
136
+            target, filters, relational_filters)
131 137
         query_result_ordering = None
132 138
         if order is not None:
133 139
             query_result_ordering = utils.parse_query_order(order)
@@ -221,7 +227,9 @@ class MongoDbDatasource(object):
221 227
     #@param act function : the caller method
222 228
     #@param **kwargs other arguments
223 229
     #@return sum of results (if it's an array it will result in a concat)
224
-    def __act_on_abstract(self, target, filters, relational_filters, act, **kwargs):
230
+    def __act_on_abstract(self,
231
+        target, filters, relational_filters, act, **kwargs):
232
+
225 233
         result = list() if act == self.select else 0
226 234
         if not target.is_abstract():
227 235
             target_childs = target

Loading…
Cancel
Save