mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
Show formatted output instead of raw HTML for job stdout in browsable API.
This commit is contained in:
@@ -20,6 +20,7 @@ from django.db.models import Q, Count, Sum
|
|||||||
from django.db import IntegrityError, transaction
|
from django.db import IntegrityError, transaction
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
@@ -2263,7 +2264,7 @@ class UnifiedJobStdout(RetrieveAPIView):
|
|||||||
content, start, end, absolute_end = unified_job.result_stdout_raw_limited(start_line, end_line)
|
content, start, end, absolute_end = unified_job.result_stdout_raw_limited(start_line, end_line)
|
||||||
if content_only:
|
if content_only:
|
||||||
headers = conv.produce_headers()
|
headers = conv.produce_headers()
|
||||||
body = conv.convert(content, full=False)
|
body = conv.convert(content, full=False) # Escapes any HTML that may be in content.
|
||||||
data = '\n'.join([headers, body])
|
data = '\n'.join([headers, body])
|
||||||
data = '<div class="nocode body_foreground body_background">%s</div>' % data
|
data = '<div class="nocode body_foreground body_background">%s</div>' % data
|
||||||
else:
|
else:
|
||||||
@@ -2271,6 +2272,8 @@ class UnifiedJobStdout(RetrieveAPIView):
|
|||||||
# Fix ugly grey background used by default.
|
# Fix ugly grey background used by default.
|
||||||
data = data.replace('.body_background { background-color: #AAAAAA; }',
|
data = data.replace('.body_background { background-color: #AAAAAA; }',
|
||||||
'.body_background { background-color: #f5f5f5; }')
|
'.body_background { background-color: #f5f5f5; }')
|
||||||
|
if request.accepted_renderer.format == 'api':
|
||||||
|
return Response(mark_safe(data))
|
||||||
if request.accepted_renderer.format == 'json':
|
if request.accepted_renderer.format == 'json':
|
||||||
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user