avoid lookup of content_type for description when summarizing object_roles

This commit is contained in:
AlanCoding 2016-08-22 14:41:55 -04:00
parent ac2f0bdf57
commit 26ce3a4773
2 changed files with 10 additions and 5 deletions

View File

@ -326,7 +326,7 @@ class BaseSerializer(serializers.ModelSerializer):
roles[field.name] = {
'id': role.id,
'name': role.name,
'description': role.description,
'description': role.get_description(reference_content_object=obj),
}
if len(roles) > 0:
summary_fields['object_roles'] = roles

View File

@ -164,17 +164,22 @@ class Role(models.Model):
global role_names
return role_names[self.role_field]
@property
def description(self):
def get_description(self, reference_content_object=None):
global role_descriptions
description = role_descriptions[self.role_field]
if '%s' in description and self.content_type:
model = self.content_type.model_class()
if reference_content_object:
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()
description = description % model_name
return description
description = property(get_description)
@staticmethod
def rebuild_role_ancestor_list(additions, removals):
'''