diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-01-15 13:00:58 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-15 16:30:00 +0000 |
commit | e024aab39cc75d8c0c6068bae07dfb0e758e7157 (patch) | |
tree | 45b3619d9b71f213064cfca396984033153f376c /bitbake | |
parent | fcb20f9dfd076f7d35f2a1b7b6767eb4033897c2 (diff) | |
download | poky-e024aab39cc75d8c0c6068bae07dfb0e758e7157.tar.gz |
bitbake: toastergui: streamline construction of filter objects
In line with comments from review, remove the QuerysetFilter
class (redundant) and convert ProjectFilters into a class
with static methods.
[YOCTO #8738]
(Bitbake rev: 59379bf6467029223045c5ebef868729d8e02c86)
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')
-rw-r--r-- | bitbake/lib/toaster/toastergui/querysetfilter.py | 24 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/tablefilter.py | 38 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/tables.py | 35 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/widgets.py | 1 |
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 @@ | |||
1 | class 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 @@ | |||
22 | from django.db.models import Q, Max, Min | 22 | from django.db.models import Q, Max, Min |
23 | from django.utils import dateparse, timezone | 23 | from django.utils import dateparse, timezone |
24 | from datetime import timedelta | 24 | from datetime import timedelta |
25 | from querysetfilter import QuerysetFilter | ||
26 | 25 | ||
27 | class TableFilter(object): | 26 | class 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 | ||
214 | class TableFilterActionDateRange(TableFilterAction): | 207 | class 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 | ||
22 | from toastergui.widgets import ToasterTable | 22 | from toastergui.widgets import ToasterTable |
23 | from toastergui.querysetfilter import QuerysetFilter | ||
24 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project | 23 | from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project |
25 | from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task | 24 | from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task |
26 | from orm.models import ProjectTarget | 25 | from orm.models import ProjectTarget |
@@ -37,9 +36,13 @@ from toastergui.tablefilter import TableFilterActionDateRange | |||
37 | from toastergui.tablefilter import TableFilterActionDay | 36 | from toastergui.tablefilter import TableFilterActionDay |
38 | 37 | ||
39 | class ProjectFilters(object): | 38 | class 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 | ||
44 | class LayersTable(ToasterTable): | 47 | class 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 | |||
32 | from django.core.serializers.json import DjangoJSONEncoder | 32 | from django.core.serializers.json import DjangoJSONEncoder |
33 | from django.core.exceptions import FieldError | 33 | from django.core.exceptions import FieldError |
34 | from django.conf.urls import url, patterns | 34 | from django.conf.urls import url, patterns |
35 | from toastergui.querysetfilter import QuerysetFilter | ||
36 | 35 | ||
37 | import types | 36 | import types |
38 | import json | 37 | import json |