summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/widgets.py
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2016-05-10 11:39:04 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-16 23:32:41 +0100
commit909f1b7bf83d17efd06bcf470364385efe2704be (patch)
tree25b87ef6c5141c06e7537b5d37f5ce88310443fb /bitbake/lib/toaster/toastergui/widgets.py
parent51738f9fa5aa07f19f24dd4a55b1fd8d210c6b3f (diff)
downloadpoky-909f1b7bf83d17efd06bcf470364385efe2704be.tar.gz
bitbake: toaster: get rid of using reduce
Replaced compicated calls of reduce with more clear code. As reduce was removed from python 3 this change is mandatory for the code to work on both pythons. Here is an example change for illustration purposes: original code: querydict = dict(zip(or_keys, or_values)) query = reduce(operator.or_, map(lambda x: __get_q_for_val(x, querydict[x]), [k for k in querydict]))) replaced with: query = None for key, val in zip(or_keys, or_values): x = __get_q_for_val(k, val) query = query | x if query else x [YOCTO #9584] (Bitbake rev: 0a25b723431602dc5eeb10a4002872c05b390f23) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/widgets.py')
-rw-r--r--bitbake/lib/toaster/toastergui/widgets.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py
index d2ef5d3dba..0f103505b2 100644
--- a/bitbake/lib/toaster/toastergui/widgets.py
+++ b/bitbake/lib/toaster/toastergui/widgets.py
@@ -243,18 +243,23 @@ class ToasterTable(TemplateView):
243 raise Exception("Search fields aren't defined in the model %s" 243 raise Exception("Search fields aren't defined in the model %s"
244 % self.queryset.model) 244 % self.queryset.model)
245 245
246 search_queries = [] 246 search_queries = None
247 for st in search_term.split(" "): 247 for st in search_term.split(" "):
248 q_map = [Q(**{field + '__icontains': st}) 248 queries = None
249 for field in self.queryset.model.search_allowed_fields] 249 for field in self.queryset.model.search_allowed_fields:
250 250 query = Q(**{field + '__icontains': st})
251 search_queries.append(reduce(operator.or_, q_map)) 251 if queries:
252 252 queries |= query
253 search_queries = reduce(operator.and_, search_queries) 253 else:
254 queries = query
255
256 if search_queries:
257 search_queries &= queries
258 else:
259 search_queries = queries
254 260
255 self.queryset = self.queryset.filter(search_queries) 261 self.queryset = self.queryset.filter(search_queries)
256 262
257
258 def get_data(self, request, **kwargs): 263 def get_data(self, request, **kwargs):
259 """ 264 """
260 Returns the data for the page requested with the specified 265 Returns the data for the page requested with the specified