Add a include_labels option in the TestView model. This works
the opposite from exclude_labels.
Risk: High
Visibility: Low
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2399 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/new_tko/tko/models.py b/new_tko/tko/models.py
index 89aba22..fd4e462 100644
--- a/new_tko/tko/models.py
+++ b/new_tko/tko/models.py
@@ -334,10 +334,11 @@
if not label_names:
return []
query = TestLabel.objects.filter(name__in=label_names).values('id')
- return [label['id'] for label in query]
+ return [str(label['id']) for label in query]
def get_query_set_with_joins(self, filter_data, include_host_labels=False):
+ include_labels = filter_data.pop('include_labels', [])
exclude_labels = filter_data.pop('exclude_labels', [])
query_set = self.get_query_set()
joined = False
@@ -347,11 +348,21 @@
query_set = self._add_label_joins(query_set)
joined = True
+ include_label_ids = self._get_label_ids_from_names(include_labels)
+ if include_label_ids:
+ # TODO: Factor this out like what's done with attributes
+ condition = ('test_labels_tests_include.testlabel_id IN (%s)' %
+ ','.join(include_label_ids))
+ query_set = self._add_join(query_set, 'test_labels_tests',
+ join_key='test_id',
+ suffix='_include',
+ join_condition=condition)
+ joined = True
+
exclude_label_ids = self._get_label_ids_from_names(exclude_labels)
if exclude_label_ids:
condition = ('test_labels_tests_exclude.testlabel_id IN (%s)' %
- ','.join(str(label_id)
- for label_id in exclude_label_ids))
+ ','.join(exclude_label_ids))
query_set = self._add_join(query_set, 'test_labels_tests',
join_key='test_id',
suffix='_exclude',