mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 13:41:28 -03:30
Merge pull request #6712 from AlanCoding/host_sublist
Optimize inventory hosts sublist
This commit is contained in:
commit
724a33c945
@ -368,12 +368,16 @@ class ListCreateAPIView(ListAPIView, generics.ListCreateAPIView):
|
||||
|
||||
|
||||
class ParentMixin(object):
|
||||
parent_object = None
|
||||
|
||||
def get_parent_object(self):
|
||||
if self.parent_object is not None:
|
||||
return self.parent_object
|
||||
parent_filter = {
|
||||
self.lookup_field: self.kwargs.get(self.lookup_field, None),
|
||||
}
|
||||
return get_object_or_404(self.parent_model, **parent_filter)
|
||||
self.parent_object = get_object_or_404(self.parent_model, **parent_filter)
|
||||
return self.parent_object
|
||||
|
||||
def check_parent_access(self, parent=None):
|
||||
parent = parent or self.get_parent_object()
|
||||
|
||||
@ -1966,6 +1966,7 @@ class InventoryHostsList(SubListCreateAttachDetachAPIView):
|
||||
parent_model = Inventory
|
||||
relationship = 'hosts'
|
||||
parent_key = 'inventory'
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
|
||||
class HostGroupsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView):
|
||||
@ -2224,6 +2225,7 @@ class GroupHostsList(ControlledByScmMixin, SubListCreateAttachDetachAPIView):
|
||||
serializer_class = HostSerializer
|
||||
parent_model = Group
|
||||
relationship = 'hosts'
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
def update_raw_data(self, data):
|
||||
data.pop('inventory', None)
|
||||
@ -2250,6 +2252,7 @@ class GroupAllHostsList(SubListAPIView):
|
||||
serializer_class = HostSerializer
|
||||
parent_model = Group
|
||||
relationship = 'hosts'
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
def get_queryset(self):
|
||||
parent = self.get_parent_object()
|
||||
@ -2606,6 +2609,7 @@ class InventorySourceHostsList(SubListAPIView):
|
||||
parent_model = InventorySource
|
||||
relationship = 'hosts'
|
||||
new_in_148 = True
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
|
||||
class InventorySourceGroupsList(SubListAPIView):
|
||||
@ -3934,6 +3938,7 @@ class JobEventHostsList(SubListAPIView):
|
||||
parent_model = JobEvent
|
||||
relationship = 'hosts'
|
||||
view_name = _('Job Event Hosts List')
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
|
||||
class BaseJobEventsList(SubListAPIView):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user