Add a checkbox 'exclude "only if needed" labels' to host lists in AFE, checked by default in the create job view.
-add exclude_only_if_needed_labels argument to get_hosts() and get_num_hosts() RPCs
-move some code from tko.models.TestViewManager up into model_logic, since AFE now needs it to create a custom join for doing many-valued exclusion



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2405 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 3b1f99c..167f04d 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -90,27 +90,33 @@
     models.Host.smart_get(id).delete()
 
 
-def get_hosts(multiple_labels=[], **filter_data):
+def get_hosts(multiple_labels=[], exclude_only_if_needed_labels=False,
+              **filter_data):
     """\
     multiple_labels: match hosts in all of the labels given.  Should be a
     list of label names.
+    exclude_only_if_needed_labels: exclude hosts with at least one
+    "only_if_needed" label applied.
     """
-    filter_data['extra_args'] = (
-        rpc_utils.extra_host_filters(multiple_labels))
-    hosts = models.Host.list_objects(filter_data)
-    for host in hosts:
-        host_obj = models.Host.objects.get(id=host['id'])
-        host['labels'] = [label.name
-                          for label in host_obj.labels.all()]
+    hosts = rpc_utils.get_host_query(multiple_labels,
+                                     exclude_only_if_needed_labels,
+                                     filter_data)
+    host_dicts = []
+    for host_obj in hosts:
+        host_dict = host_obj.get_object_dict()
+        host_dict['labels'] = [label.name for label in host_obj.labels.all()]
         platform = host_obj.platform()
-        host['platform'] = platform and platform.name or None
-    return rpc_utils.prepare_for_serialization(hosts)
+        host_dict['platform'] = platform and platform.name or None
+        host_dicts.append(host_dict)
+    return rpc_utils.prepare_for_serialization(host_dicts)
 
 
-def get_num_hosts(multiple_labels=[], **filter_data):
-    filter_data['extra_args'] = (
-        rpc_utils.extra_host_filters(multiple_labels))
-    return models.Host.query_count(filter_data)
+def get_num_hosts(multiple_labels=[], exclude_only_if_needed_labels=False,
+                  **filter_data):
+    hosts = rpc_utils.get_host_query(multiple_labels,
+                                     exclude_only_if_needed_labels,
+                                     filter_data)
+    return hosts.count()
 
 
 # tests