mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 12:49:46 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
fcb20f9dfd
commit
e024aab39c
@@ -1,24 +0,0 @@
|
|||||||
class QuerysetFilter(object):
|
|
||||||
""" Filter for a queryset """
|
|
||||||
|
|
||||||
def __init__(self, criteria=None):
|
|
||||||
self.criteria = None
|
|
||||||
if criteria:
|
|
||||||
self.set_criteria(criteria)
|
|
||||||
|
|
||||||
def set_criteria(self, criteria):
|
|
||||||
"""
|
|
||||||
criteria is an instance of django.db.models.Q;
|
|
||||||
see https://docs.djangoproject.com/en/1.9/ref/models/querysets/#q-objects
|
|
||||||
"""
|
|
||||||
self.criteria = criteria
|
|
||||||
|
|
||||||
def filter(self, queryset):
|
|
||||||
"""
|
|
||||||
Filter queryset according to the criteria for this filter,
|
|
||||||
returning the filtered queryset
|
|
||||||
"""
|
|
||||||
if self.criteria:
|
|
||||||
return queryset.filter(self.criteria)
|
|
||||||
else:
|
|
||||||
return queryset
|
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
from django.db.models import Q, Max, Min
|
from django.db.models import Q, Max, Min
|
||||||
from django.utils import dateparse, timezone
|
from django.utils import dateparse, timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from querysetfilter import QuerysetFilter
|
|
||||||
|
|
||||||
class TableFilter(object):
|
class TableFilter(object):
|
||||||
"""
|
"""
|
||||||
@@ -118,10 +117,10 @@ class TableFilterAction(object):
|
|||||||
ToasterTable
|
ToasterTable
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, title, queryset_filter):
|
def __init__(self, name, title, criteria):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.title = title
|
self.title = title
|
||||||
self.queryset_filter = queryset_filter
|
self.criteria = criteria
|
||||||
|
|
||||||
# set in subclasses
|
# set in subclasses
|
||||||
self.type = None
|
self.type = None
|
||||||
@@ -132,11 +131,13 @@ class TableFilterAction(object):
|
|||||||
the structure of this string depends on the type of action;
|
the structure of this string depends on the type of action;
|
||||||
it's ignored for a toggle filter action, which is just on or off
|
it's ignored for a toggle filter action, which is just on or off
|
||||||
"""
|
"""
|
||||||
if not params:
|
pass
|
||||||
return
|
|
||||||
|
|
||||||
def filter(self, queryset):
|
def filter(self, queryset):
|
||||||
return self.queryset_filter.filter(queryset)
|
if self.criteria:
|
||||||
|
return queryset.filter(self.criteria)
|
||||||
|
else:
|
||||||
|
return queryset
|
||||||
|
|
||||||
def to_json(self, queryset):
|
def to_json(self, queryset):
|
||||||
""" Dump as a JSON object """
|
""" Dump as a JSON object """
|
||||||
@@ -167,16 +168,12 @@ class TableFilterActionDay(TableFilterAction):
|
|||||||
YESTERDAY = 'yesterday'
|
YESTERDAY = 'yesterday'
|
||||||
|
|
||||||
def __init__(self, name, title, field, day,
|
def __init__(self, name, title, field, day,
|
||||||
queryset_filter = QuerysetFilter(), query_helper = TableFilterQueryHelper()):
|
query_helper = TableFilterQueryHelper()):
|
||||||
"""
|
"""
|
||||||
field: (string) the datetime field to filter by
|
field: (string) the datetime field to filter by
|
||||||
day: (string) "today" or "yesterday"
|
day: (string) "today" or "yesterday"
|
||||||
"""
|
"""
|
||||||
super(TableFilterActionDay, self).__init__(
|
super(TableFilterActionDay, self).__init__(name, title, None)
|
||||||
name,
|
|
||||||
title,
|
|
||||||
queryset_filter
|
|
||||||
)
|
|
||||||
self.type = 'day'
|
self.type = 'day'
|
||||||
self.field = field
|
self.field = field
|
||||||
self.day = day
|
self.day = day
|
||||||
@@ -189,8 +186,6 @@ class TableFilterActionDay(TableFilterAction):
|
|||||||
depending on when the filtering is applied
|
depending on when the filtering is applied
|
||||||
"""
|
"""
|
||||||
|
|
||||||
criteria = None
|
|
||||||
date_str = None
|
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
|
|
||||||
if self.day == self.YESTERDAY:
|
if self.day == self.YESTERDAY:
|
||||||
@@ -201,15 +196,13 @@ class TableFilterActionDay(TableFilterAction):
|
|||||||
|
|
||||||
wanted_date_str = wanted_date.strftime('%Y-%m-%d')
|
wanted_date_str = wanted_date.strftime('%Y-%m-%d')
|
||||||
|
|
||||||
criteria = self.query_helper.dateStringsToQ(
|
self.criteria = self.query_helper.dateStringsToQ(
|
||||||
self.field,
|
self.field,
|
||||||
wanted_date_str,
|
wanted_date_str,
|
||||||
wanted_date_str
|
wanted_date_str
|
||||||
)
|
)
|
||||||
|
|
||||||
self.queryset_filter.set_criteria(criteria)
|
return queryset.filter(self.criteria)
|
||||||
|
|
||||||
return self.queryset_filter.filter(queryset)
|
|
||||||
|
|
||||||
class TableFilterActionDateRange(TableFilterAction):
|
class TableFilterActionDateRange(TableFilterAction):
|
||||||
"""
|
"""
|
||||||
@@ -218,14 +211,14 @@ class TableFilterActionDateRange(TableFilterAction):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, title, field,
|
def __init__(self, name, title, field,
|
||||||
queryset_filter = QuerysetFilter(), query_helper = TableFilterQueryHelper()):
|
query_helper = TableFilterQueryHelper()):
|
||||||
"""
|
"""
|
||||||
field: (string) the field to find the max/min range from in the queryset
|
field: (string) the field to find the max/min range from in the queryset
|
||||||
"""
|
"""
|
||||||
super(TableFilterActionDateRange, self).__init__(
|
super(TableFilterActionDateRange, self).__init__(
|
||||||
name,
|
name,
|
||||||
title,
|
title,
|
||||||
queryset_filter
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
self.type = 'daterange'
|
self.type = 'daterange'
|
||||||
@@ -248,17 +241,16 @@ class TableFilterActionDateRange(TableFilterAction):
|
|||||||
try:
|
try:
|
||||||
date_from_str, date_to_str = params.split(',')
|
date_from_str, date_to_str = params.split(',')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.queryset_filter.set_criteria(None)
|
self.criteria = None
|
||||||
return
|
return
|
||||||
|
|
||||||
# one of the values required for the filter is missing, so set
|
# one of the values required for the filter is missing, so set
|
||||||
# it to the one which was supplied
|
# it to the one which was supplied
|
||||||
criteria = self.query_helper.dateStringsToQ(
|
self.criteria = self.query_helper.dateStringsToQ(
|
||||||
self.field,
|
self.field,
|
||||||
date_from_str,
|
date_from_str,
|
||||||
date_to_str
|
date_to_str
|
||||||
)
|
)
|
||||||
self.queryset_filter.set_criteria(criteria)
|
|
||||||
|
|
||||||
def to_json(self, queryset):
|
def to_json(self, queryset):
|
||||||
""" Dump as a JSON object """
|
""" Dump as a JSON object """
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
from toastergui.widgets import ToasterTable
|
from toastergui.widgets import ToasterTable
|
||||||
from toastergui.querysetfilter import QuerysetFilter
|
|
||||||
from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
|
from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project
|
||||||
from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task
|
from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task
|
||||||
from orm.models import ProjectTarget
|
from orm.models import ProjectTarget
|
||||||
@@ -37,9 +36,13 @@ from toastergui.tablefilter import TableFilterActionDateRange
|
|||||||
from toastergui.tablefilter import TableFilterActionDay
|
from toastergui.tablefilter import TableFilterActionDay
|
||||||
|
|
||||||
class ProjectFilters(object):
|
class ProjectFilters(object):
|
||||||
def __init__(self, project_layers):
|
@staticmethod
|
||||||
self.in_project = QuerysetFilter(Q(layer_version__in=project_layers))
|
def in_project(project_layers):
|
||||||
self.not_in_project = QuerysetFilter(~Q(layer_version__in=project_layers))
|
return Q(layer_version__in=project_layers)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def not_in_project(project_layers):
|
||||||
|
return ~(ProjectFilters.in_project(project_layers))
|
||||||
|
|
||||||
class LayersTable(ToasterTable):
|
class LayersTable(ToasterTable):
|
||||||
"""Table of layers in Toaster"""
|
"""Table of layers in Toaster"""
|
||||||
@@ -71,13 +74,13 @@ class LayersTable(ToasterTable):
|
|||||||
in_project_action = TableFilterActionToggle(
|
in_project_action = TableFilterActionToggle(
|
||||||
"in_project",
|
"in_project",
|
||||||
"Layers added to this project",
|
"Layers added to this project",
|
||||||
QuerysetFilter(criteria)
|
criteria
|
||||||
)
|
)
|
||||||
|
|
||||||
not_in_project_action = TableFilterActionToggle(
|
not_in_project_action = TableFilterActionToggle(
|
||||||
"not_in_project",
|
"not_in_project",
|
||||||
"Layers not added to this project",
|
"Layers not added to this project",
|
||||||
QuerysetFilter(~criteria)
|
~criteria
|
||||||
)
|
)
|
||||||
|
|
||||||
in_current_project_filter.add_action(in_project_action)
|
in_current_project_filter.add_action(in_project_action)
|
||||||
@@ -217,8 +220,6 @@ class MachinesTable(ToasterTable):
|
|||||||
def setup_filters(self, *args, **kwargs):
|
def setup_filters(self, *args, **kwargs):
|
||||||
project = Project.objects.get(pk=kwargs['pid'])
|
project = Project.objects.get(pk=kwargs['pid'])
|
||||||
|
|
||||||
project_filters = ProjectFilters(self.project_layers)
|
|
||||||
|
|
||||||
in_current_project_filter = TableFilter(
|
in_current_project_filter = TableFilter(
|
||||||
"in_current_project",
|
"in_current_project",
|
||||||
"Filter by project machines"
|
"Filter by project machines"
|
||||||
@@ -227,13 +228,13 @@ class MachinesTable(ToasterTable):
|
|||||||
in_project_action = TableFilterActionToggle(
|
in_project_action = TableFilterActionToggle(
|
||||||
"in_project",
|
"in_project",
|
||||||
"Machines provided by layers added to this project",
|
"Machines provided by layers added to this project",
|
||||||
project_filters.in_project
|
ProjectFilters.in_project(self.project_layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
not_in_project_action = TableFilterActionToggle(
|
not_in_project_action = TableFilterActionToggle(
|
||||||
"not_in_project",
|
"not_in_project",
|
||||||
"Machines provided by layers not added to this project",
|
"Machines provided by layers not added to this project",
|
||||||
project_filters.not_in_project
|
ProjectFilters.not_in_project(self.project_layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
in_current_project_filter.add_action(in_project_action)
|
in_current_project_filter.add_action(in_project_action)
|
||||||
@@ -350,8 +351,6 @@ class RecipesTable(ToasterTable):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
def setup_filters(self, *args, **kwargs):
|
def setup_filters(self, *args, **kwargs):
|
||||||
project_filters = ProjectFilters(self.project_layers)
|
|
||||||
|
|
||||||
table_filter = TableFilter(
|
table_filter = TableFilter(
|
||||||
'in_current_project',
|
'in_current_project',
|
||||||
'Filter by project recipes'
|
'Filter by project recipes'
|
||||||
@@ -360,13 +359,13 @@ class RecipesTable(ToasterTable):
|
|||||||
in_project_action = TableFilterActionToggle(
|
in_project_action = TableFilterActionToggle(
|
||||||
'in_project',
|
'in_project',
|
||||||
'Recipes provided by layers added to this project',
|
'Recipes provided by layers added to this project',
|
||||||
project_filters.in_project
|
ProjectFilters.in_project(self.project_layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
not_in_project_action = TableFilterActionToggle(
|
not_in_project_action = TableFilterActionToggle(
|
||||||
'not_in_project',
|
'not_in_project',
|
||||||
'Recipes provided by layers not added to this project',
|
'Recipes provided by layers not added to this project',
|
||||||
project_filters.not_in_project
|
ProjectFilters.not_in_project(self.project_layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
table_filter.add_action(in_project_action)
|
table_filter.add_action(in_project_action)
|
||||||
@@ -1140,13 +1139,13 @@ class BuildsTable(ToasterTable):
|
|||||||
successful_builds_action = TableFilterActionToggle(
|
successful_builds_action = TableFilterActionToggle(
|
||||||
'successful_builds',
|
'successful_builds',
|
||||||
'Successful builds',
|
'Successful builds',
|
||||||
QuerysetFilter(Q(outcome=Build.SUCCEEDED))
|
Q(outcome=Build.SUCCEEDED)
|
||||||
)
|
)
|
||||||
|
|
||||||
failed_builds_action = TableFilterActionToggle(
|
failed_builds_action = TableFilterActionToggle(
|
||||||
'failed_builds',
|
'failed_builds',
|
||||||
'Failed builds',
|
'Failed builds',
|
||||||
QuerysetFilter(Q(outcome=Build.FAILED))
|
Q(outcome=Build.FAILED)
|
||||||
)
|
)
|
||||||
|
|
||||||
outcome_filter.add_action(successful_builds_action)
|
outcome_filter.add_action(successful_builds_action)
|
||||||
@@ -1226,13 +1225,13 @@ class BuildsTable(ToasterTable):
|
|||||||
with_failed_tasks_action = TableFilterActionToggle(
|
with_failed_tasks_action = TableFilterActionToggle(
|
||||||
'with_failed_tasks',
|
'with_failed_tasks',
|
||||||
'Builds with failed tasks',
|
'Builds with failed tasks',
|
||||||
QuerysetFilter(criteria)
|
criteria
|
||||||
)
|
)
|
||||||
|
|
||||||
without_failed_tasks_action = TableFilterActionToggle(
|
without_failed_tasks_action = TableFilterActionToggle(
|
||||||
'without_failed_tasks',
|
'without_failed_tasks',
|
||||||
'Builds without failed tasks',
|
'Builds without failed tasks',
|
||||||
QuerysetFilter(~criteria)
|
~criteria
|
||||||
)
|
)
|
||||||
|
|
||||||
failed_tasks_filter.add_action(with_failed_tasks_action)
|
failed_tasks_filter.add_action(with_failed_tasks_action)
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ from django.template import Context, Template
|
|||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.conf.urls import url, patterns
|
from django.conf.urls import url, patterns
|
||||||
from toastergui.querysetfilter import QuerysetFilter
|
|
||||||
|
|
||||||
import types
|
import types
|
||||||
import json
|
import json
|
||||||
|
|||||||
Reference in New Issue
Block a user