mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
improved query efficiently, refactored code
This commit is contained in:
parent
3f9f28322c
commit
98c8499f2f
@ -2481,13 +2481,10 @@ class InventoryInventorySourcesUpdate(RetrieveAPIView):
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
inventory = self.get_object()
|
||||
update_data = []
|
||||
for inventory_source in inventory.inventory_sources.all():
|
||||
if inventory_source.source == '':
|
||||
continue
|
||||
else:
|
||||
details = {'inventory_source': inventory_source.pk,
|
||||
'can_update': inventory_source.can_update}
|
||||
update_data.append(details)
|
||||
for inventory_source in inventory.inventory_sources.exclude(source=''):
|
||||
details = {'inventory_source': inventory_source.pk,
|
||||
'can_update': inventory_source.can_update}
|
||||
update_data.append(details)
|
||||
return Response(update_data)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@ -2495,19 +2492,16 @@ class InventoryInventorySourcesUpdate(RetrieveAPIView):
|
||||
update_data = []
|
||||
successes = 0
|
||||
failures = 0
|
||||
for inventory_source in inventory.inventory_sources.all():
|
||||
for inventory_source in inventory.inventory_sources.exclude(source=''):
|
||||
details = {'inventory_source': inventory_source.pk, 'status': None}
|
||||
can_update = inventory_source.can_update
|
||||
project_update = False
|
||||
|
||||
if inventory_source.source == 'scm' and inventory_source.update_on_project_update:
|
||||
if not request.user or not request.user.can_access(Project, 'start', inventory_source.source_project):
|
||||
details['status'] = _('You do not have permission to update project `{}`').format(inventory_source.source_project.name)
|
||||
can_update = False
|
||||
else:
|
||||
project_update = True
|
||||
if inventory_source.source == '':
|
||||
continue
|
||||
if can_update:
|
||||
if project_update:
|
||||
details['project_update'] = inventory_source.source_project.update().id
|
||||
|
||||
@ -112,7 +112,10 @@ class TestInventoryInventorySourcesUpdate:
|
||||
return [InventorySource(pk=1, source=is_source, source_project=Project,
|
||||
update_on_project_update=is_up_on_proj,
|
||||
can_update=can_update, update=lambda:InventoryUpdate)]
|
||||
|
||||
|
||||
def exclude(self, **kwargs):
|
||||
return self.all()
|
||||
|
||||
Inventory = namedtuple('Inventory', ['inventory_sources'])
|
||||
obj = Inventory(inventory_sources=InventorySources())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user