diff options
| author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-05-10 11:39:04 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-02 08:24:03 +0100 |
| commit | bbc6e754e84115099722c78259868ee0e64bdc3c (patch) | |
| tree | c4f386f62dbe0cf70353612cd48b06db38d92613 /bitbake/lib/toaster/toastergui/widgets.py | |
| parent | 7c44d883b432cbededb1e2620d3823e603fd25c0 (diff) | |
| download | poky-bbc6e754e84115099722c78259868ee0e64bdc3c.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: 249d0bc6094ec9f369a02b78d8ed634a239e5ee4)
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.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py index 4117031830..0f972d940e 100644 --- a/bitbake/lib/toaster/toastergui/widgets.py +++ b/bitbake/lib/toaster/toastergui/widgets.py | |||
| @@ -239,14 +239,20 @@ class ToasterTable(TemplateView): | |||
| 239 | raise Exception("Search fields aren't defined in the model %s" | 239 | raise Exception("Search fields aren't defined in the model %s" |
| 240 | % self.queryset.model) | 240 | % self.queryset.model) |
| 241 | 241 | ||
| 242 | search_queries = [] | 242 | search_queries = None |
| 243 | for st in search_term.split(" "): | 243 | for st in search_term.split(" "): |
| 244 | q_map = [Q(**{field + '__icontains': st}) | 244 | queries = None |
| 245 | for field in self.queryset.model.search_allowed_fields] | 245 | for field in self.queryset.model.search_allowed_fields: |
| 246 | 246 | query = Q(**{field + '__icontains': st}) | |
| 247 | search_queries.append(reduce(operator.or_, q_map)) | 247 | if queries: |
| 248 | 248 | queries |= query | |
| 249 | search_queries = reduce(operator.and_, search_queries) | 249 | else: |
| 250 | queries = query | ||
| 251 | |||
| 252 | if search_queries: | ||
| 253 | search_queries &= queries | ||
| 254 | else: | ||
| 255 | search_queries = queries | ||
| 250 | 256 | ||
| 251 | self.queryset = self.queryset.filter(search_queries) | 257 | self.queryset = self.queryset.filter(search_queries) |
| 252 | 258 | ||
