mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
AC-1040 Change type to job_type when unified_job_template is included in summary_fields.
This commit is contained in:
@@ -197,12 +197,13 @@ class GenericAPIView(generics.GenericAPIView, APIView):
|
|||||||
# appropriate metadata about the fields that should be supplied.
|
# appropriate metadata about the fields that should be supplied.
|
||||||
serializer = self.get_serializer()
|
serializer = self.get_serializer()
|
||||||
actions['GET'] = serializer.metadata()
|
actions['GET'] = serializer.metadata()
|
||||||
# Inject the type field choices into GET options as well as on
|
if hasattr(serializer, 'get_types'):
|
||||||
# the metadata itself.
|
# Inject the type field choices into GET options as well as on
|
||||||
if 'type' in actions['GET']:
|
# the metadata itself.
|
||||||
actions['GET']['type']['type'] = 'multiple choice'
|
if 'type' in actions['GET']:
|
||||||
actions['GET']['type']['choices'] = serializer.get_type_choices()
|
actions['GET']['type']['type'] = 'multiple choice'
|
||||||
ret['types'] = serializer.get_types()
|
actions['GET']['type']['choices'] = serializer.get_type_choices()
|
||||||
|
ret['types'] = serializer.get_types()
|
||||||
if actions:
|
if actions:
|
||||||
ret['actions'] = actions
|
ret['actions'] = actions
|
||||||
if getattr(self, 'search_fields', None):
|
if getattr(self, 'search_fields', None):
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ from rest_framework.compat import get_concrete_model
|
|||||||
from rest_framework import fields
|
from rest_framework import fields
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# Django-Polymorphic
|
||||||
|
from polymorphic import PolymorphicModel
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import *
|
from awx.main.models import *
|
||||||
from awx.main.utils import update_scm_url, get_type_for_model, get_model_for_type
|
from awx.main.utils import update_scm_url, get_type_for_model, get_model_for_type
|
||||||
@@ -35,7 +38,7 @@ from awx.main.utils import update_scm_url, get_type_for_model, get_model_for_typ
|
|||||||
logger = logging.getLogger('awx.api.serializers')
|
logger = logging.getLogger('awx.api.serializers')
|
||||||
|
|
||||||
# Fields that should be summarized regardless of object type.
|
# Fields that should be summarized regardless of object type.
|
||||||
DEFAULT_SUMMARY_FIELDS = ('name', 'description',)
|
DEFAULT_SUMMARY_FIELDS = ('name', 'description')#, 'type')
|
||||||
|
|
||||||
# Keys are fields (foreign keys) where, if found on an instance, summary info
|
# Keys are fields (foreign keys) where, if found on an instance, summary info
|
||||||
# should be added to the serialized data. Values are a tuple of field names on
|
# should be added to the serialized data. Values are a tuple of field names on
|
||||||
@@ -68,7 +71,7 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed',),
|
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed',),
|
||||||
'job_template': DEFAULT_SUMMARY_FIELDS,
|
'job_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
||||||
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('type',),
|
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('job_type',),
|
||||||
'last_job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'last_job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
'last_job_host_summary': DEFAULT_SUMMARY_FIELDS + ('failed',),
|
'last_job_host_summary': DEFAULT_SUMMARY_FIELDS + ('failed',),
|
||||||
'last_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'last_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
@@ -272,11 +275,12 @@ class BaseSerializer(serializers.ModelSerializer):
|
|||||||
for field in related_fields:
|
for field in related_fields:
|
||||||
fval = getattr(fkval, field, None)
|
fval = getattr(fkval, field, None)
|
||||||
if fval is None and field == 'type':
|
if fval is None and field == 'type':
|
||||||
if type(fkval) == UnifiedJobTemplate:
|
if isinstance(fkval, PolymorphicModel):
|
||||||
obj_actual = UnifiedJobTemplate.objects.get(id=fkval.id)
|
fkval = fkval.get_real_instance()
|
||||||
summary_fields[fk][field] = get_type_for_model(obj_actual._get_unified_job_class())
|
fval = get_type_for_model(fkval)
|
||||||
else:
|
elif fval is None and field == 'job_type' and isinstance(fkval, UnifiedJobTemplate):
|
||||||
summary_fields[fk][field] = get_type_for_model(fkval)
|
fkval = fkval.get_real_instance()
|
||||||
|
fval = get_type_for_model(fkval._get_unified_job_class())
|
||||||
if fval is not None:
|
if fval is not None:
|
||||||
summary_fields[fk][field] = fval
|
summary_fields[fk][field] = fval
|
||||||
# Can be raised by the reverse accessor for a OneToOneField.
|
# Can be raised by the reverse accessor for a OneToOneField.
|
||||||
|
|||||||
Reference in New Issue
Block a user