mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 20:30:46 -03:30
Merge pull request #4201 from beeankha/helper_method_in_serializer
Add Helper Method in Serializer for get_summary_fields
Reviewed-by: Yanis Guenane
https://github.com/Spredzy
This commit is contained in:
commit
de02df4907
@ -4680,6 +4680,23 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
obj._prefetched_objects_cache[related_manager.prefetch_cache_name] = list(related_manager.all())
|
||||
return related_manager.all()
|
||||
|
||||
def _summarize_parent_ujt(self, obj, fk, summary_fields):
|
||||
summary_keys = {'job': 'job_template',
|
||||
'workflow_job_template_node': 'workflow_job_template',
|
||||
'schedule': 'unified_job_template'}
|
||||
if fk not in summary_keys:
|
||||
return
|
||||
related_obj = getattr(obj, summary_keys[fk], None)
|
||||
summary_fields[get_type_for_model(related_obj)] = []
|
||||
item = {}
|
||||
fields = SUMMARIZABLE_FK_FIELDS[summary_keys[fk]]
|
||||
if related_obj is not None:
|
||||
for field in fields:
|
||||
fval = getattr(related_obj, field, None)
|
||||
if fval is not None:
|
||||
item[field] = fval
|
||||
summary_fields[get_type_for_model(related_obj)].append(item)
|
||||
|
||||
def get_summary_fields(self, obj):
|
||||
summary_fields = OrderedDict()
|
||||
for fk, related_fields in self._local_summarizable_fk_fields:
|
||||
@ -4690,33 +4707,7 @@ class ActivityStreamSerializer(BaseSerializer):
|
||||
if m2m_list:
|
||||
summary_fields[fk] = []
|
||||
for thisItem in m2m_list:
|
||||
if fk == 'job':
|
||||
summary_fields['job_template'] = []
|
||||
job_template_item = {}
|
||||
job_template_fields = SUMMARIZABLE_FK_FIELDS['job_template']
|
||||
job_template = getattr(thisItem, 'job_template', None)
|
||||
if job_template is not None:
|
||||
for field in job_template_fields:
|
||||
fval = getattr(job_template, field, None)
|
||||
if fval is not None:
|
||||
job_template_item[field] = fval
|
||||
summary_fields['job_template'].append(job_template_item)
|
||||
if fk == 'workflow_job_template_node':
|
||||
summary_fields['workflow_job_template'] = []
|
||||
workflow_job_template_item = {}
|
||||
workflow_job_template_fields = SUMMARIZABLE_FK_FIELDS['workflow_job_template']
|
||||
workflow_job_template = getattr(thisItem, 'workflow_job_template', None)
|
||||
if workflow_job_template is not None:
|
||||
for field in workflow_job_template_fields:
|
||||
fval = getattr(workflow_job_template, field, None)
|
||||
if fval is not None:
|
||||
workflow_job_template_item[field] = fval
|
||||
summary_fields['workflow_job_template'].append(workflow_job_template_item)
|
||||
if fk == 'schedule':
|
||||
unified_job_template = getattr(thisItem, 'unified_job_template', None)
|
||||
if unified_job_template is not None:
|
||||
summary_fields[get_type_for_model(unified_job_template)] = {'id': unified_job_template.id,
|
||||
'name': unified_job_template.name}
|
||||
self._summarize_parent_ujt(thisItem, fk, summary_fields)
|
||||
thisItemDict = {}
|
||||
for field in related_fields:
|
||||
fval = getattr(thisItem, field, None)
|
||||
|
||||
@ -39,13 +39,13 @@ export default function BuildAnchor($log, $filter) {
|
||||
case 'schedule':
|
||||
// schedule urls depend on the resource they're associated with
|
||||
if (activity.summary_fields.job_template){
|
||||
url += 'templates/job_template/' + activity.summary_fields.job_template.id + '/schedules/' + obj.id;
|
||||
url += 'templates/job_template/' + activity.summary_fields.job_template[0].id + '/schedules/' + obj.id;
|
||||
}
|
||||
else if (activity.summary_fields.project){
|
||||
url += 'projects/' + activity.summary_fields.project.id + '/schedules/' + obj.id;
|
||||
url += 'projects/' + activity.summary_fields.project[0].id + '/schedules/' + obj.id;
|
||||
}
|
||||
else if (activity.summary_fields.system_job_template){
|
||||
url += 'management_jobs/' + activity.summary_fields.system_job_template.id + '/schedules/edit/' + obj.id;
|
||||
url += 'management_jobs/management_jobs/' + activity.summary_fields.system_job_template[0].id + '/schedules/edit/' + obj.id;
|
||||
}
|
||||
// urls for inventory sync schedules currently depend on having an inventory id and group id
|
||||
else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user