diff options
author | Elliot Smith <elliot.smith@intel.com> | 2016-01-15 13:00:50 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-15 16:28:43 +0000 |
commit | 94031bb30bdaf665d0c8c68b591fcb7a17b6674d (patch) | |
tree | 8acc66e940e77cb60d7c4f2464a485809422c2d5 /lib/toaster/toastergui/tables.py | |
parent | e0590fc8103afeb4c5e613a826057555c8193d59 (diff) | |
download | bitbake-94031bb30bdaf665d0c8c68b591fcb7a17b6674d.tar.gz |
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]
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 'lib/toaster/toastergui/tables.py')
-rw-r--r-- | lib/toaster/toastergui/tables.py | 132 |
1 files changed, 87 insertions, 45 deletions
diff --git a/lib/toaster/toastergui/tables.py b/lib/toaster/toastergui/tables.py index 116cff3f4..a0991ec3e 100644 --- a/lib/toaster/toastergui/tables.py +++ b/lib/toaster/toastergui/tables.py @@ -28,6 +28,8 @@ from django.conf.urls import url from django.core.urlresolvers import reverse from django.views.generic import TemplateView +from toastergui.tablefilter import TableFilter, TableFilterActionToggle + class ProjectFilters(object): def __init__(self, project_layers): self.in_project = QuerysetFilter(Q(layer_version__in=project_layers)) @@ -53,16 +55,28 @@ class LayersTable(ToasterTable): project = Project.objects.get(pk=kwargs['pid']) self.project_layers = ProjectLayer.objects.filter(project=project) + in_current_project_filter = TableFilter( + "in_current_project", + "Filter by project layers" + ) + criteria = Q(projectlayer__in=self.project_layers) - in_project_filter = QuerysetFilter(criteria) - not_in_project_filter = QuerysetFilter(~criteria) - self.add_filter(title="Filter by project layers", - name="in_current_project", - filter_actions=[ - self.make_filter_action("in_project", "Layers added to this project", in_project_filter), - self.make_filter_action("not_in_project", "Layers not added to this project", not_in_project_filter) - ]) + in_project_filter_action = TableFilterActionToggle( + "in_project", + "Layers added to this project", + QuerysetFilter(criteria) + ) + + not_in_project_filter_action = TableFilterActionToggle( + "not_in_project", + "Layers not added to this project", + QuerysetFilter(~criteria) + ) + + in_current_project_filter.add_action(in_project_filter_action) + in_current_project_filter.add_action(not_in_project_filter_action) + self.add_filter(in_current_project_filter) def setup_queryset(self, *args, **kwargs): prj = Project.objects.get(pk = kwargs['pid']) @@ -199,12 +213,26 @@ class MachinesTable(ToasterTable): project_filters = ProjectFilters(self.project_layers) - self.add_filter(title="Filter by project machines", - name="in_current_project", - filter_actions=[ - self.make_filter_action("in_project", "Machines provided by layers added to this project", project_filters.in_project), - self.make_filter_action("not_in_project", "Machines provided by layers not added to this project", project_filters.not_in_project) - ]) + in_current_project_filter = TableFilter( + "in_current_project", + "Filter by project machines" + ) + + in_project_filter_action = TableFilterActionToggle( + "in_project", + "Machines provided by layers added to this project", + project_filters.in_project + ) + + not_in_project_filter_action = TableFilterActionToggle( + "not_in_project", + "Machines provided by layers not added to this project", + project_filters.not_in_project + ) + + in_current_project_filter.add_action(in_project_filter_action) + in_current_project_filter.add_action(not_in_project_filter_action) + self.add_filter(in_current_project_filter) def setup_queryset(self, *args, **kwargs): prj = Project.objects.get(pk = kwargs['pid']) @@ -318,12 +346,26 @@ class RecipesTable(ToasterTable): def setup_filters(self, *args, **kwargs): project_filters = ProjectFilters(self.project_layers) - self.add_filter(title="Filter by project recipes", - name="in_current_project", - filter_actions=[ - self.make_filter_action("in_project", "Recipes provided by layers added to this project", project_filters.in_project), - self.make_filter_action("not_in_project", "Recipes provided by layers not added to this project", project_filters.not_in_project) - ]) + table_filter = TableFilter( + 'in_current_project', + 'Filter by project recipes' + ) + + in_project_filter_action = TableFilterActionToggle( + 'in_project', + 'Recipes provided by layers added to this project', + project_filters.in_project + ) + + not_in_project_filter_action = TableFilterActionToggle( + 'not_in_project', + 'Recipes provided by layers not added to this project', + project_filters.not_in_project + ) + + table_filter.add_action(in_project_filter_action) + table_filter.add_action(not_in_project_filter_action) + self.add_filter(table_filter) def setup_queryset(self, *args, **kwargs): prj = Project.objects.get(pk = kwargs['pid']) @@ -1070,47 +1112,47 @@ class BuildsTable(ToasterTable): def setup_filters(self, *args, **kwargs): # outcomes - filter_only_successful_builds = QuerysetFilter(Q(outcome=Build.SUCCEEDED)) - successful_builds_filter = self.make_filter_action( + outcome_filter = TableFilter( + 'outcome_filter', + 'Filter builds by outcome' + ) + + successful_builds_filter_action = TableFilterActionToggle( 'successful_builds', 'Successful builds', - filter_only_successful_builds + QuerysetFilter(Q(outcome=Build.SUCCEEDED)) ) - filter_only_failed_builds = QuerysetFilter(Q(outcome=Build.FAILED)) - failed_builds_filter = self.make_filter_action( + failed_builds_filter_action = TableFilterActionToggle( 'failed_builds', 'Failed builds', - filter_only_failed_builds + QuerysetFilter(Q(outcome=Build.FAILED)) ) - self.add_filter(title='Filter builds by outcome', - name='outcome_filter', - filter_actions = [ - successful_builds_filter, - failed_builds_filter - ]) + outcome_filter.add_action(successful_builds_filter_action) + outcome_filter.add_action(failed_builds_filter_action) + self.add_filter(outcome_filter) # failed tasks + failed_tasks_filter = TableFilter( + 'failed_tasks_filter', + 'Filter builds by failed tasks' + ) + criteria = Q(task_build__outcome=Task.OUTCOME_FAILED) - filter_only_builds_with_failed_tasks = QuerysetFilter(criteria) - with_failed_tasks_filter = self.make_filter_action( + + with_failed_tasks_filter_action = TableFilterActionToggle( 'with_failed_tasks', 'Builds with failed tasks', - filter_only_builds_with_failed_tasks + QuerysetFilter(criteria) ) - criteria = ~Q(task_build__outcome=Task.OUTCOME_FAILED) - filter_only_builds_without_failed_tasks = QuerysetFilter(criteria) - without_failed_tasks_filter = self.make_filter_action( + without_failed_tasks_filter_action = TableFilterActionToggle( 'without_failed_tasks', 'Builds without failed tasks', - filter_only_builds_without_failed_tasks + QuerysetFilter(~criteria) ) - self.add_filter(title='Filter builds by failed tasks', - name='failed_tasks_filter', - filter_actions = [ - with_failed_tasks_filter, - without_failed_tasks_filter - ]) + failed_tasks_filter.add_action(with_failed_tasks_filter_action) + failed_tasks_filter.add_action(without_failed_tasks_filter_action) + self.add_filter(failed_tasks_filter) |