summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/tables.py
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-01-15 13:00:50 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-15 16:29:59 +0000
commit809046c6fbd544907b5d5f3bb554b71724c74661 (patch)
tree9a20e81100395ba67934f3e865c6e9356f4e0232 /bitbake/lib/toaster/toastergui/tables.py
parent294579b531d5a96a17aa863554e71f4680d35812 (diff)
downloadpoky-809046c6fbd544907b5d5f3bb554b71724c74661.tar.gz
bitbake: toastergui: refactor ToasterTable filtering
The filter code for ToasterTable was difficult to follow and inflexible (not allowing different types of filter, for example). Refactor to a set of filter classes to make the structure cleaner and provide the flexibility needed for other filter types (e.g. date range filter). [YOCTO #8738] (Bitbake rev: 94031bb30bdaf665d0c8c68b591fcb7a17b6674d) Signed-off-by: Elliot Smith <elliot.smith@intel.com> 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/tables.py')
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py132
1 files changed, 87 insertions, 45 deletions
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index 116cff3f43..a0991ec3ea 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -28,6 +28,8 @@ from django.conf.urls import url
28from django.core.urlresolvers import reverse 28from django.core.urlresolvers import reverse
29from django.views.generic import TemplateView 29from django.views.generic import TemplateView
30 30
31from toastergui.tablefilter import TableFilter, TableFilterActionToggle
32
31class ProjectFilters(object): 33class ProjectFilters(object):
32 def __init__(self, project_layers): 34 def __init__(self, project_layers):
33 self.in_project = QuerysetFilter(Q(layer_version__in=project_layers)) 35 self.in_project = QuerysetFilter(Q(layer_version__in=project_layers))
@@ -53,16 +55,28 @@ class LayersTable(ToasterTable):
53 project = Project.objects.get(pk=kwargs['pid']) 55 project = Project.objects.get(pk=kwargs['pid'])
54 self.project_layers = ProjectLayer.objects.filter(project=project) 56 self.project_layers = ProjectLayer.objects.filter(project=project)
55 57
58 in_current_project_filter = TableFilter(
59 "in_current_project",
60 "Filter by project layers"
61 )
62
56 criteria = Q(projectlayer__in=self.project_layers) 63 criteria = Q(projectlayer__in=self.project_layers)
57 in_project_filter = QuerysetFilter(criteria)
58 not_in_project_filter = QuerysetFilter(~criteria)
59 64
60 self.add_filter(title="Filter by project layers", 65 in_project_filter_action = TableFilterActionToggle(
61 name="in_current_project", 66 "in_project",
62 filter_actions=[ 67 "Layers added to this project",
63 self.make_filter_action("in_project", "Layers added to this project", in_project_filter), 68 QuerysetFilter(criteria)
64 self.make_filter_action("not_in_project", "Layers not added to this project", not_in_project_filter) 69 )
65 ]) 70
71 not_in_project_filter_action = TableFilterActionToggle(
72 "not_in_project",
73 "Layers not added to this project",
74 QuerysetFilter(~criteria)
75 )
76
77 in_current_project_filter.add_action(in_project_filter_action)
78 in_current_project_filter.add_action(not_in_project_filter_action)
79 self.add_filter(in_current_project_filter)
66 80
67 def setup_queryset(self, *args, **kwargs): 81 def setup_queryset(self, *args, **kwargs):
68 prj = Project.objects.get(pk = kwargs['pid']) 82 prj = Project.objects.get(pk = kwargs['pid'])
@@ -199,12 +213,26 @@ class MachinesTable(ToasterTable):
199 213
200 project_filters = ProjectFilters(self.project_layers) 214 project_filters = ProjectFilters(self.project_layers)
201 215
202 self.add_filter(title="Filter by project machines", 216 in_current_project_filter = TableFilter(
203 name="in_current_project", 217 "in_current_project",
204 filter_actions=[ 218 "Filter by project machines"
205 self.make_filter_action("in_project", "Machines provided by layers added to this project", project_filters.in_project), 219 )
206 self.make_filter_action("not_in_project", "Machines provided by layers not added to this project", project_filters.not_in_project) 220
207 ]) 221 in_project_filter_action = TableFilterActionToggle(
222 "in_project",
223 "Machines provided by layers added to this project",
224 project_filters.in_project
225 )
226
227 not_in_project_filter_action = TableFilterActionToggle(
228 "not_in_project",
229 "Machines provided by layers not added to this project",
230 project_filters.not_in_project
231 )
232
233 in_current_project_filter.add_action(in_project_filter_action)
234 in_current_project_filter.add_action(not_in_project_filter_action)
235 self.add_filter(in_current_project_filter)
208 236
209 def setup_queryset(self, *args, **kwargs): 237 def setup_queryset(self, *args, **kwargs):
210 prj = Project.objects.get(pk = kwargs['pid']) 238 prj = Project.objects.get(pk = kwargs['pid'])
@@ -318,12 +346,26 @@ class RecipesTable(ToasterTable):
318 def setup_filters(self, *args, **kwargs): 346 def setup_filters(self, *args, **kwargs):
319 project_filters = ProjectFilters(self.project_layers) 347 project_filters = ProjectFilters(self.project_layers)
320 348
321 self.add_filter(title="Filter by project recipes", 349 table_filter = TableFilter(
322 name="in_current_project", 350 'in_current_project',
323 filter_actions=[ 351 'Filter by project recipes'
324 self.make_filter_action("in_project", "Recipes provided by layers added to this project", project_filters.in_project), 352 )
325 self.make_filter_action("not_in_project", "Recipes provided by layers not added to this project", project_filters.not_in_project) 353
326 ]) 354 in_project_filter_action = TableFilterActionToggle(
355 'in_project',
356 'Recipes provided by layers added to this project',
357 project_filters.in_project
358 )
359
360 not_in_project_filter_action = TableFilterActionToggle(
361 'not_in_project',
362 'Recipes provided by layers not added to this project',
363 project_filters.not_in_project
364 )
365
366 table_filter.add_action(in_project_filter_action)
367 table_filter.add_action(not_in_project_filter_action)
368 self.add_filter(table_filter)
327 369
328 def setup_queryset(self, *args, **kwargs): 370 def setup_queryset(self, *args, **kwargs):
329 prj = Project.objects.get(pk = kwargs['pid']) 371 prj = Project.objects.get(pk = kwargs['pid'])
@@ -1070,47 +1112,47 @@ class BuildsTable(ToasterTable):
1070 1112
1071 def setup_filters(self, *args, **kwargs): 1113 def setup_filters(self, *args, **kwargs):
1072 # outcomes 1114 # outcomes
1073 filter_only_successful_builds = QuerysetFilter(Q(outcome=Build.SUCCEEDED)) 1115 outcome_filter = TableFilter(
1074 successful_builds_filter = self.make_filter_action( 1116 'outcome_filter',
1117 'Filter builds by outcome'
1118 )
1119
1120 successful_builds_filter_action = TableFilterActionToggle(
1075 'successful_builds', 1121 'successful_builds',
1076 'Successful builds', 1122 'Successful builds',
1077 filter_only_successful_builds 1123 QuerysetFilter(Q(outcome=Build.SUCCEEDED))
1078 ) 1124 )
1079 1125
1080 filter_only_failed_builds = QuerysetFilter(Q(outcome=Build.FAILED)) 1126 failed_builds_filter_action = TableFilterActionToggle(
1081 failed_builds_filter = self.make_filter_action(
1082 'failed_builds', 1127 'failed_builds',
1083 'Failed builds', 1128 'Failed builds',
1084 filter_only_failed_builds 1129 QuerysetFilter(Q(outcome=Build.FAILED))
1085 ) 1130 )
1086 1131
1087 self.add_filter(title='Filter builds by outcome', 1132 outcome_filter.add_action(successful_builds_filter_action)
1088 name='outcome_filter', 1133 outcome_filter.add_action(failed_builds_filter_action)
1089 filter_actions = [ 1134 self.add_filter(outcome_filter)
1090 successful_builds_filter,
1091 failed_builds_filter
1092 ])
1093 1135
1094 # failed tasks 1136 # failed tasks
1137 failed_tasks_filter = TableFilter(
1138 'failed_tasks_filter',
1139 'Filter builds by failed tasks'
1140 )
1141
1095 criteria = Q(task_build__outcome=Task.OUTCOME_FAILED) 1142 criteria = Q(task_build__outcome=Task.OUTCOME_FAILED)
1096 filter_only_builds_with_failed_tasks = QuerysetFilter(criteria) 1143
1097 with_failed_tasks_filter = self.make_filter_action( 1144 with_failed_tasks_filter_action = TableFilterActionToggle(
1098 'with_failed_tasks', 1145 'with_failed_tasks',
1099 'Builds with failed tasks', 1146 'Builds with failed tasks',
1100 filter_only_builds_with_failed_tasks 1147 QuerysetFilter(criteria)
1101 ) 1148 )
1102 1149
1103 criteria = ~Q(task_build__outcome=Task.OUTCOME_FAILED) 1150 without_failed_tasks_filter_action = TableFilterActionToggle(
1104 filter_only_builds_without_failed_tasks = QuerysetFilter(criteria)
1105 without_failed_tasks_filter = self.make_filter_action(
1106 'without_failed_tasks', 1151 'without_failed_tasks',
1107 'Builds without failed tasks', 1152 'Builds without failed tasks',
1108 filter_only_builds_without_failed_tasks 1153 QuerysetFilter(~criteria)
1109 ) 1154 )
1110 1155
1111 self.add_filter(title='Filter builds by failed tasks', 1156 failed_tasks_filter.add_action(with_failed_tasks_filter_action)
1112 name='failed_tasks_filter', 1157 failed_tasks_filter.add_action(without_failed_tasks_filter_action)
1113 filter_actions = [ 1158 self.add_filter(failed_tasks_filter)
1114 with_failed_tasks_filter,
1115 without_failed_tasks_filter
1116 ])