summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/toaster/toastergui/querysetfilter.py24
-rw-r--r--bitbake/lib/toaster/toastergui/tablefilter.py38
-rw-r--r--bitbake/lib/toaster/toastergui/tables.py35
-rw-r--r--bitbake/lib/toaster/toastergui/widgets.py1
4 files changed, 32 insertions, 66 deletions
diff --git a/bitbake/lib/toaster/toastergui/querysetfilter.py b/bitbake/lib/toaster/toastergui/querysetfilter.py
deleted file mode 100644
index 10cc988bce..0000000000
--- a/bitbake/lib/toaster/toastergui/querysetfilter.py
+++ /dev/null
@@ -1,24 +0,0 @@
1class QuerysetFilter(object):
2 """ Filter for a queryset """
3
4 def __init__(self, criteria=None):
5 self.criteria = None
6 if criteria:
7 self.set_criteria(criteria)
8
9 def set_criteria(self, criteria):
10 """
11 criteria is an instance of django.db.models.Q;
12 see https://docs.djangoproject.com/en/1.9/ref/models/querysets/#q-objects
13 """
14 self.criteria = criteria
15
16 def filter(self, queryset):
17 """
18 Filter queryset according to the criteria for this filter,
19 returning the filtered queryset
20 """
21 if self.criteria:
22 return queryset.filter(self.criteria)
23 else:
24 return queryset
diff --git a/bitbake/lib/toaster/toastergui/tablefilter.py b/bitbake/lib/toaster/toastergui/tablefilter.py
index bd8decd0e3..9d15bcff0d 100644
--- a/bitbake/lib/toaster/toastergui/tablefilter.py
+++ b/bitbake/lib/toaster/toastergui/tablefilter.py
@@ -22,7 +22,6 @@
22from django.db.models import Q, Max, Min 22from django.db.models import Q, Max, Min
23from django.utils import dateparse, timezone 23from django.utils import dateparse, timezone
24from datetime import timedelta 24from datetime import timedelta
25from querysetfilter import QuerysetFilter
26 25
27class TableFilter(object): 26class TableFilter(object):
28 """ 27 """
@@ -118,10 +117,10 @@ class TableFilterAction(object):
118 ToasterTable 117 ToasterTable
119 """ 118 """
120 119
121 def __init__(self, name, title, queryset_filter): 120 def __init__(self, name, title, criteria):
122 self.name = name 121 self.name = name
123 self.title = title 122 self.title = title
124 self.queryset_filter = queryset_filter 123 self.criteria = criteria
125 124
126 # set in subclasses 125 # set in subclasses
127 self.type = None 126 self.type = None
@@ -132,11 +131,13 @@ class TableFilterAction(object):
132 the structure of this string depends on the type of action; 131 the structure of this string depends on the type of action;
133 it's ignored for a toggle filter action, which is just on or off 132 it's ignored for a toggle filter action, which is just on or off
134 """ 133 """
135 if not params: 134 pass
136 return
137 135
138 def filter(self, queryset): 136 def filter(self, queryset):
139 return self.queryset_filter.filter(queryset) 137 if self.criteria:
138 return queryset.filter(self.criteria)
139 else:
140 return queryset
140 141
141 def to_json(self, queryset): 142 def to_json(self, queryset):
142 """ Dump as a JSON object """ 143 """ Dump as a JSON object """
@@ -167,16 +168,12 @@ class TableFilterActionDay(TableFilterAction):
167 YESTERDAY = 'yesterday' 168 YESTERDAY = 'yesterday'
168 169
169 def __init__(self, name, title, field, day, 170 def __init__(self, name, title, field, day,
170 queryset_filter = QuerysetFilter(), query_helper = TableFilterQueryHelper()): 171 query_helper = TableFilterQueryHelper()):
171 """ 172 """
172 field: (string) the datetime field to filter by 173 field: (string) the datetime field to filter by
173 day: (string) "today" or "yesterday" 174 day: (string) "today" or "yesterday"
174 """ 175 """
175 super(TableFilterActionDay, self).__init__( 176 super(TableFilterActionDay, self).__init__(name, title, None)
176 name,
177 title,
178 queryset_filter
179 )
180 self.type = 'day' 177 self.type = 'day'
181 self.field = field 178 self.field = field
182 self.day = day 179 self.day = day
@@ -189,8 +186,6 @@ class TableFilterActionDay(TableFilterAction):
189 depending on when the filtering is applied 186 depending on when the filtering is applied
190 """ 187 """
191 188
192 criteria = None
193 date_str = None
194 now = timezone.now() 189 now = timezone.now()
195 190
196 if self.day == self.YESTERDAY: 191 if self.day == self.YESTERDAY:
@@ -201,15 +196,13 @@ class TableFilterActionDay(TableFilterAction):
201 196
202 wanted_date_str = wanted_date.strftime('%Y-%m-%d') 197 wanted_date_str = wanted_date.strftime('%Y-%m-%d')
203 198
204 criteria = self.query_helper.dateStringsToQ( 199 self.criteria = self.query_helper.dateStringsToQ(
205 self.field, 200 self.field,
206 wanted_date_str, 201 wanted_date_str,
207 wanted_date_str 202 wanted_date_str
208 ) 203 )
209 204
210 self.queryset_filter.set_criteria(criteria) 205 return queryset.filter(self.criteria)
211
212 return self.queryset_filter.filter(queryset)
213 206
214class TableFilterActionDateRange(TableFilterAction): 207class TableFilterActionDateRange(TableFilterAction):
215 """ 208 """
@@ -218,14 +211,14 @@ class TableFilterActionDateRange(TableFilterAction):
218 """ 211 """
219 212
220 def __init__(self, name, title, field, 213 def __init__(self, name, title, field,
221 queryset_filter = QuerysetFilter(), query_helper = TableFilterQueryHelper()): 214 query_helper = TableFilterQueryHelper()):
222 """ 215 """
223 field: (string) the field to find the max/min range from in the queryset 216 field: (string) the field to find the max/min range from in the queryset
224 """ 217 """
225 super(TableFilterActionDateRange, self).__init__( 218 super(TableFilterActionDateRange, self).__init__(
226 name, 219 name,
227 title, 220 title,
228 queryset_filter 221 None
229 ) 222 )
230 223
231 self.type = 'daterange' 224 self.type = 'daterange'
@@ -248,17 +241,16 @@ class TableFilterActionDateRange(TableFilterAction):
248 try: 241 try:
249 date_from_str, date_to_str = params.split(',') 242 date_from_str, date_to_str = params.split(',')
250 except ValueError: 243 except ValueError:
251 self.queryset_filter.set_criteria(None) 244 self.criteria = None
252 return 245 return
253 246
254 # one of the values required for the filter is missing, so set 247 # one of the values required for the filter is missing, so set
255 # it to the one which was supplied 248 # it to the one which was supplied
256 criteria = self.query_helper.dateStringsToQ( 249 self.criteria = self.query_helper.dateStringsToQ(
257 self.field, 250 self.field,
258 date_from_str, 251 date_from_str,
259 date_to_str 252 date_to_str
260 ) 253 )
261 self.queryset_filter.set_criteria(criteria)
262 254
263 def to_json(self, queryset): 255 def to_json(self, queryset):
264 """ Dump as a JSON object """ 256 """ Dump as a JSON object """
diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py
index d0ed49625d..b7d977ea03 100644
--- a/bitbake/lib/toaster/toastergui/tables.py
+++ b/bitbake/lib/toaster/toastergui/tables.py
@@ -20,7 +20,6 @@
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 21
22from toastergui.widgets import ToasterTable 22from toastergui.widgets import ToasterTable
23from toastergui.querysetfilter import QuerysetFilter
24from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project 23from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
25from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task 24from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task
26from orm.models import ProjectTarget 25from orm.models import ProjectTarget
@@ -37,9 +36,13 @@ from toastergui.tablefilter import TableFilterActionDateRange
37from toastergui.tablefilter import TableFilterActionDay 36from toastergui.tablefilter import TableFilterActionDay
38 37
39class ProjectFilters(object): 38class ProjectFilters(object):
40 def __init__(self, project_layers): 39 @staticmethod
41 self.in_project = QuerysetFilter(Q(layer_version__in=project_layers)) 40 def in_project(project_layers):
42 self.not_in_project = QuerysetFilter(~Q(layer_version__in=project_layers)) 41 return Q(layer_version__in=project_layers)
42
43 @staticmethod
44 def not_in_project(project_layers):
45 return ~(ProjectFilters.in_project(project_layers))
43 46
44class LayersTable(ToasterTable): 47class LayersTable(ToasterTable):
45 """Table of layers in Toaster""" 48 """Table of layers in Toaster"""
@@ -71,13 +74,13 @@ class LayersTable(ToasterTable):
71 in_project_action = TableFilterActionToggle( 74 in_project_action = TableFilterActionToggle(
72 "in_project", 75 "in_project",
73 "Layers added to this project", 76 "Layers added to this project",
74 QuerysetFilter(criteria) 77 criteria
75 ) 78 )
76 79
77 not_in_project_action = TableFilterActionToggle( 80 not_in_project_action = TableFilterActionToggle(
78 "not_in_project", 81 "not_in_project",
79 "Layers not added to this project", 82 "Layers not added to this project",
80 QuerysetFilter(~criteria) 83 ~criteria
81 ) 84 )
82 85
83 in_current_project_filter.add_action(in_project_action) 86 in_current_project_filter.add_action(in_project_action)
@@ -217,8 +220,6 @@ class MachinesTable(ToasterTable):
217 def setup_filters(self, *args, **kwargs): 220 def setup_filters(self, *args, **kwargs):
218 project = Project.objects.get(pk=kwargs['pid']) 221 project = Project.objects.get(pk=kwargs['pid'])
219 222
220 project_filters = ProjectFilters(self.project_layers)
221
222 in_current_project_filter = TableFilter( 223 in_current_project_filter = TableFilter(
223 "in_current_project", 224 "in_current_project",
224 "Filter by project machines" 225 "Filter by project machines"
@@ -227,13 +228,13 @@ class MachinesTable(ToasterTable):
227 in_project_action = TableFilterActionToggle( 228 in_project_action = TableFilterActionToggle(
228 "in_project", 229 "in_project",
229 "Machines provided by layers added to this project", 230 "Machines provided by layers added to this project",
230 project_filters.in_project 231 ProjectFilters.in_project(self.project_layers)
231 ) 232 )
232 233
233 not_in_project_action = TableFilterActionToggle( 234 not_in_project_action = TableFilterActionToggle(
234 "not_in_project", 235 "not_in_project",
235 "Machines provided by layers not added to this project", 236 "Machines provided by layers not added to this project",
236 project_filters.not_in_project 237 ProjectFilters.not_in_project(self.project_layers)
237 ) 238 )
238 239
239 in_current_project_filter.add_action(in_project_action) 240 in_current_project_filter.add_action(in_project_action)
@@ -350,8 +351,6 @@ class RecipesTable(ToasterTable):
350 return context 351 return context
351 352
352 def setup_filters(self, *args, **kwargs): 353 def setup_filters(self, *args, **kwargs):
353 project_filters = ProjectFilters(self.project_layers)
354
355 table_filter = TableFilter( 354 table_filter = TableFilter(
356 'in_current_project', 355 'in_current_project',
357 'Filter by project recipes' 356 'Filter by project recipes'
@@ -360,13 +359,13 @@ class RecipesTable(ToasterTable):
360 in_project_action = TableFilterActionToggle( 359 in_project_action = TableFilterActionToggle(
361 'in_project', 360 'in_project',
362 'Recipes provided by layers added to this project', 361 'Recipes provided by layers added to this project',
363 project_filters.in_project 362 ProjectFilters.in_project(self.project_layers)
364 ) 363 )
365 364
366 not_in_project_action = TableFilterActionToggle( 365 not_in_project_action = TableFilterActionToggle(
367 'not_in_project', 366 'not_in_project',
368 'Recipes provided by layers not added to this project', 367 'Recipes provided by layers not added to this project',
369 project_filters.not_in_project 368 ProjectFilters.not_in_project(self.project_layers)
370 ) 369 )
371 370
372 table_filter.add_action(in_project_action) 371 table_filter.add_action(in_project_action)
@@ -1140,13 +1139,13 @@ class BuildsTable(ToasterTable):
1140 successful_builds_action = TableFilterActionToggle( 1139 successful_builds_action = TableFilterActionToggle(
1141 'successful_builds', 1140 'successful_builds',
1142 'Successful builds', 1141 'Successful builds',
1143 QuerysetFilter(Q(outcome=Build.SUCCEEDED)) 1142 Q(outcome=Build.SUCCEEDED)
1144 ) 1143 )
1145 1144
1146 failed_builds_action = TableFilterActionToggle( 1145 failed_builds_action = TableFilterActionToggle(
1147 'failed_builds', 1146 'failed_builds',
1148 'Failed builds', 1147 'Failed builds',
1149 QuerysetFilter(Q(outcome=Build.FAILED)) 1148 Q(outcome=Build.FAILED)
1150 ) 1149 )
1151 1150
1152 outcome_filter.add_action(successful_builds_action) 1151 outcome_filter.add_action(successful_builds_action)
@@ -1226,13 +1225,13 @@ class BuildsTable(ToasterTable):
1226 with_failed_tasks_action = TableFilterActionToggle( 1225 with_failed_tasks_action = TableFilterActionToggle(
1227 'with_failed_tasks', 1226 'with_failed_tasks',
1228 'Builds with failed tasks', 1227 'Builds with failed tasks',
1229 QuerysetFilter(criteria) 1228 criteria
1230 ) 1229 )
1231 1230
1232 without_failed_tasks_action = TableFilterActionToggle( 1231 without_failed_tasks_action = TableFilterActionToggle(
1233 'without_failed_tasks', 1232 'without_failed_tasks',
1234 'Builds without failed tasks', 1233 'Builds without failed tasks',
1235 QuerysetFilter(~criteria) 1234 ~criteria
1236 ) 1235 )
1237 1236
1238 failed_tasks_filter.add_action(with_failed_tasks_action) 1237 failed_tasks_filter.add_action(with_failed_tasks_action)
diff --git a/bitbake/lib/toaster/toastergui/widgets.py b/bitbake/lib/toaster/toastergui/widgets.py
index bc081b818b..d9328d4cdc 100644
--- a/bitbake/lib/toaster/toastergui/widgets.py
+++ b/bitbake/lib/toaster/toastergui/widgets.py
@@ -32,7 +32,6 @@ from django.template import Context, Template
32from django.core.serializers.json import DjangoJSONEncoder 32from django.core.serializers.json import DjangoJSONEncoder
33from django.core.exceptions import FieldError 33from django.core.exceptions import FieldError
34from django.conf.urls import url, patterns 34from django.conf.urls import url, patterns
35from toastergui.querysetfilter import QuerysetFilter
36 35
37import types 36import types
38import json 37import json