diff options
Diffstat (limited to 'bitbake/lib/toaster')
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 64 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/widgets.py | 20 |
2 files changed, 57 insertions, 27 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index e78b0dab89..22d1a0ce6a 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -229,10 +229,18 @@ OR_VALUE_SEPARATOR = "|" | |||
229 | DESCENDING = "-" | 229 | DESCENDING = "-" |
230 | 230 | ||
231 | def __get_q_for_val(name, value): | 231 | def __get_q_for_val(name, value): |
232 | if "OR" in value: | 232 | if "OR" in value or "AND" in value: |
233 | return reduce(operator.or_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("OR") ])) | 233 | result = None |
234 | for x in value.split("OR"): | ||
235 | x = __get_q_for_val(name, x) | ||
236 | result = result | x if result else x | ||
237 | return result | ||
234 | if "AND" in value: | 238 | if "AND" in value: |
235 | return reduce(operator.and_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("AND") ])) | 239 | result = None |
240 | for x in value.split("AND"): | ||
241 | x = __get_q_for_val(name, x) | ||
242 | result = result & x if result else x | ||
243 | return result | ||
236 | if value.startswith("NOT"): | 244 | if value.startswith("NOT"): |
237 | value = value[3:] | 245 | value = value[3:] |
238 | if value == 'None': | 246 | if value == 'None': |
@@ -251,14 +259,18 @@ def _get_filtering_query(filter_string): | |||
251 | and_keys = search_terms[0].split(AND_VALUE_SEPARATOR) | 259 | and_keys = search_terms[0].split(AND_VALUE_SEPARATOR) |
252 | and_values = search_terms[1].split(AND_VALUE_SEPARATOR) | 260 | and_values = search_terms[1].split(AND_VALUE_SEPARATOR) |
253 | 261 | ||
254 | and_query = [] | 262 | and_query = None |
255 | for kv in zip(and_keys, and_values): | 263 | for kv in zip(and_keys, and_values): |
256 | or_keys = kv[0].split(OR_VALUE_SEPARATOR) | 264 | or_keys = kv[0].split(OR_VALUE_SEPARATOR) |
257 | or_values = kv[1].split(OR_VALUE_SEPARATOR) | 265 | or_values = kv[1].split(OR_VALUE_SEPARATOR) |
258 | querydict = dict(zip(or_keys, or_values)) | 266 | query = None |
259 | and_query.append(reduce(operator.or_, map(lambda x: __get_q_for_val(x, querydict[x]), [k for k in querydict]))) | 267 | for key, val in zip(or_keys, or_values): |
268 | x = __get_q_for_val(k, val) | ||
269 | query = query | x if query else x | ||
260 | 270 | ||
261 | return reduce(operator.and_, [k for k in and_query]) | 271 | and_query = and_query & query if and_query else query |
272 | |||
273 | return and_query | ||
262 | 274 | ||
263 | def _get_toggle_order(request, orderkey, toggle_reverse = False): | 275 | def _get_toggle_order(request, orderkey, toggle_reverse = False): |
264 | if toggle_reverse: | 276 | if toggle_reverse: |
@@ -295,21 +307,24 @@ def _validate_input(field_input, model): | |||
295 | # Check we are looking for a valid field | 307 | # Check we are looking for a valid field |
296 | valid_fields = model._meta.get_all_field_names() | 308 | valid_fields = model._meta.get_all_field_names() |
297 | for field in field_input_list[0].split(AND_VALUE_SEPARATOR): | 309 | for field in field_input_list[0].split(AND_VALUE_SEPARATOR): |
298 | if not reduce(lambda x, y: x or y, [ field.startswith(x) for x in valid_fields ]): | 310 | if True in [field.startswith(x) for x in valid_fields]: |
299 | return None, (field, [ x for x in valid_fields ]) | 311 | break |
312 | else: | ||
313 | return None, (field, valid_fields) | ||
300 | 314 | ||
301 | return field_input, invalid | 315 | return field_input, invalid |
302 | 316 | ||
303 | # uses search_allowed_fields in orm/models.py to create a search query | 317 | # uses search_allowed_fields in orm/models.py to create a search query |
304 | # for these fields with the supplied input text | 318 | # for these fields with the supplied input text |
305 | def _get_search_results(search_term, queryset, model): | 319 | def _get_search_results(search_term, queryset, model): |
306 | search_objects = [] | 320 | search_object = None |
307 | for st in search_term.split(" "): | 321 | for st in search_term.split(" "): |
308 | q_map = map(lambda x: Q(**{x+'__icontains': st}), | 322 | queries = None |
309 | model.search_allowed_fields) | 323 | for field in model.search_allowed_fields: |
324 | query = Q(**{x+'__icontains': st}) | ||
325 | queries = queries | query if queries else query | ||
310 | 326 | ||
311 | search_objects.append(reduce(operator.or_, q_map)) | 327 | search_object = search_object & queries if search_object else queries |
312 | search_object = reduce(operator.and_, search_objects) | ||
313 | queryset = queryset.filter(search_object) | 328 | queryset = queryset.filter(search_object) |
314 | 329 | ||
315 | return queryset | 330 | return queryset |
@@ -1938,10 +1953,10 @@ if True: | |||
1938 | if ptype == "build": | 1953 | if ptype == "build": |
1939 | mandatory_fields.append('projectversion') | 1954 | mandatory_fields.append('projectversion') |
1940 | # make sure we have values for all mandatory_fields | 1955 | # make sure we have values for all mandatory_fields |
1941 | if reduce( lambda x, y: x or y, map(lambda x: len(request.POST.get(x, '')) == 0, mandatory_fields)): | 1956 | missing = [field for field in mandatory_fields if len(request.POST.get(field, '')) == 0] |
1942 | # set alert for missing fields | 1957 | if missing: |
1943 | raise BadParameterException("Fields missing: " + | 1958 | # set alert for missing fields |
1944 | ", ".join([x for x in mandatory_fields if len(request.POST.get(x, '')) == 0 ])) | 1959 | raise BadParameterException("Fields missing: %s" % ", ".join(missing)) |
1945 | 1960 | ||
1946 | if not request.user.is_authenticated(): | 1961 | if not request.user.is_authenticated(): |
1947 | user = authenticate(username = request.POST.get('username', '_anonuser'), password = 'nopass') | 1962 | user = authenticate(username = request.POST.get('username', '_anonuser'), password = 'nopass') |
@@ -2035,13 +2050,22 @@ if True: | |||
2035 | from collections import Counter | 2050 | from collections import Counter |
2036 | freqtargets = [] | 2051 | freqtargets = [] |
2037 | try: | 2052 | try: |
2038 | freqtargets += map(lambda x: x.target, reduce(lambda x, y: x + y, map(lambda x: list(x.target_set.all()), Build.objects.filter(project = prj, outcome__lt = Build.IN_PROGRESS)))) | 2053 | btargets = sum(build.target_set.all() for build in Build.objects.filter(project=prj, outcome__lt=Build.IN_PROGRESS)) |
2039 | freqtargets += map(lambda x: x.target, reduce(lambda x, y: x + y, map(lambda x: list(x.brtarget_set.all()), BuildRequest.objects.filter(project = prj, state = BuildRequest.REQ_FAILED)))) | 2054 | brtargets = sum(br.brtarget_set.all() for br in BuildRequest.objects.filter(project = prj, state = BuildRequest.REQ_FAILED)) |
2055 | freqtargets = [x.target for x in btargets] + [x.target for x in brtargets] | ||
2040 | except TypeError: | 2056 | except TypeError: |
2041 | pass | 2057 | pass |
2042 | freqtargets = Counter(freqtargets) | 2058 | freqtargets = Counter(freqtargets) |
2043 | freqtargets = sorted(freqtargets, key = lambda x: freqtargets[x], reverse=True) | 2059 | freqtargets = sorted(freqtargets, key = lambda x: freqtargets[x], reverse=True) |
2044 | 2060 | ||
2061 | layers = [{"id": x.layercommit.pk, "orderid": x.pk, "name" : x.layercommit.layer.name, | ||
2062 | "vcs_url": x.layercommit.layer.vcs_url, "vcs_reference" : x.layercommit.get_vcs_reference(), | ||
2063 | "url": x.layercommit.layer.layer_index_url, "layerdetailurl": x.layercommit.get_detailspage_url(prj.pk), | ||
2064 | # This branch name is actually the release | ||
2065 | "branch" : {"name" : x.layercommit.get_vcs_reference(), | ||
2066 | "layersource" : x.layercommit.up_branch.layer_source.name if x.layercommit.up_branch != None else None} | ||
2067 | } for x in prj.projectlayer_set.all().order_by("id")] | ||
2068 | |||
2045 | context = { | 2069 | context = { |
2046 | "project" : prj, | 2070 | "project" : prj, |
2047 | "lvs_nos" : Layer_Version.objects.all().count(), | 2071 | "lvs_nos" : Layer_Version.objects.all().count(), |
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 | ||