mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 16:51:11 +03:00
Add ordering and various filtering for job events as requested by AC-1349
This commit is contained in:
parent
e4fd79f653
commit
053bb4eeb0
@ -29,14 +29,21 @@ def paginated(method):
|
||||
limit = min(api_settings.MAX_PAGINATE_BY, limit)
|
||||
limit = int(limit)
|
||||
|
||||
# Get the order parameter if it's given
|
||||
if request.QUERY_PARAMS.get("ordering", False):
|
||||
ordering = request.QUERY_PARAMS[ordering]
|
||||
else:
|
||||
ordering = None
|
||||
|
||||
# What page are we on?
|
||||
page = int(request.QUERY_PARAMS.get('page', 1))
|
||||
offset = (page - 1) * limit
|
||||
|
||||
# Add the limit, offset, and page variables to the keyword arguments
|
||||
# Add the limit, offset, page, and order variables to the keyword arguments
|
||||
# being sent to the underlying method.
|
||||
kwargs['limit'] = limit
|
||||
kwargs['offset'] = offset
|
||||
kwargs['ordering'] = ordering
|
||||
|
||||
# Okay, call the underlying method.
|
||||
results, count = method(self, request, *args, **kwargs)
|
||||
@ -64,3 +71,4 @@ def paginated(method):
|
||||
# Okay, we're done; return response data.
|
||||
return Response(answer)
|
||||
return func
|
||||
|
||||
|
@ -1486,12 +1486,26 @@ class JobJobPlaysList(BaseJobEventsList):
|
||||
new_in_150 = True
|
||||
|
||||
@paginated
|
||||
def get(self, request, limit, offset, *args, **kwargs):
|
||||
def get(self, request, limit, offset, ordering, *args, **kwargs):
|
||||
all_plays = []
|
||||
job = get_object_or_404(self.parent_model, pk=self.kwargs['pk'])
|
||||
|
||||
# Put together a queryset for relevant job events.
|
||||
qs = job.job_events.filter(event='playbook_on_play_start')
|
||||
if ordering is not None:
|
||||
qs = qs.order_by(ordering)
|
||||
|
||||
# This is a bit of a special case for id filtering requested by the UI
|
||||
# doing this here for the moment until/unless we need to implement more
|
||||
# complex filtering (since we aren't under a serializer)
|
||||
|
||||
if "id__in" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(id__in=[int(filter_id) for filter_id in request.QUERY_PARAMS["id__in"].split(",")])
|
||||
elif "id__gt" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(id__gt=request.QUERY_PARAMS['id__gt'])
|
||||
if "failed" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(failed=(request.QUERY_PARAMS['failed'].lower() == 'true'))
|
||||
|
||||
count = qs.count()
|
||||
|
||||
# Iterate over the relevant play events and get the details.
|
||||
@ -1540,7 +1554,7 @@ class JobJobTasksList(BaseJobEventsList):
|
||||
new_in_150 = True
|
||||
|
||||
@paginated
|
||||
def get(self, request, limit, offset, *args, **kwargs):
|
||||
def get(self, request, limit, offset, ordering, *args, **kwargs):
|
||||
"""Return aggregate data about each of the job tasks that is:
|
||||
- an immediate child of the job event
|
||||
- corresponding to the spinning up of a new task or playbook
|
||||
@ -1570,6 +1584,18 @@ class JobJobTasksList(BaseJobEventsList):
|
||||
.values('parent__id', 'event', 'changed')
|
||||
.annotate(num=Count('event'))
|
||||
.order_by('parent__id'))
|
||||
|
||||
# This is a bit of a special case for id filtering requested by the UI
|
||||
# doing this here for the moment until/unless we need to implement more
|
||||
# complex filtering (since we aren't under a serializer)
|
||||
|
||||
if "id__in" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(id__in=[int(filter_id) for filter_id in request.QUERY_PARAMS["id__in"].split(",")])
|
||||
elif "id__gt" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(id__gt=request.QUERY_PARAMS['id__gt'])
|
||||
if "failed" in request.QUERY_PARAMS:
|
||||
qs = qs.filter(failed=(request.QUERY_PARAMS['failed'].lower() == 'true'))
|
||||
|
||||
count = queryset.count()
|
||||
|
||||
# The data above will come back in a list, but we are going to
|
||||
|
Loading…
Reference in New Issue
Block a user