mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 13:25:02 -02:30
avoid lookup of content_type for description when summarizing object_roles
This commit is contained in:
@@ -326,7 +326,7 @@ class BaseSerializer(serializers.ModelSerializer):
|
|||||||
roles[field.name] = {
|
roles[field.name] = {
|
||||||
'id': role.id,
|
'id': role.id,
|
||||||
'name': role.name,
|
'name': role.name,
|
||||||
'description': role.description,
|
'description': role.get_description(reference_content_object=obj),
|
||||||
}
|
}
|
||||||
if len(roles) > 0:
|
if len(roles) > 0:
|
||||||
summary_fields['object_roles'] = roles
|
summary_fields['object_roles'] = roles
|
||||||
|
|||||||
@@ -164,17 +164,22 @@ class Role(models.Model):
|
|||||||
global role_names
|
global role_names
|
||||||
return role_names[self.role_field]
|
return role_names[self.role_field]
|
||||||
|
|
||||||
@property
|
def get_description(self, reference_content_object=None):
|
||||||
def description(self):
|
|
||||||
global role_descriptions
|
global role_descriptions
|
||||||
description = role_descriptions[self.role_field]
|
description = role_descriptions[self.role_field]
|
||||||
if '%s' in description and self.content_type:
|
if reference_content_object:
|
||||||
model = self.content_type.model_class()
|
content_type = ContentType.objects.get_for_model(reference_content_object)
|
||||||
|
else:
|
||||||
|
content_type = self.content_type
|
||||||
|
if '%s' in description and content_type:
|
||||||
|
model = content_type.model_class()
|
||||||
model_name = re.sub(r'([a-z])([A-Z])', r'\1 \2', model.__name__).lower()
|
model_name = re.sub(r'([a-z])([A-Z])', r'\1 \2', model.__name__).lower()
|
||||||
description = description % model_name
|
description = description % model_name
|
||||||
|
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
description = property(get_description)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def rebuild_role_ancestor_list(additions, removals):
|
def rebuild_role_ancestor_list(additions, removals):
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user