mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Implement AC-634 - Additional bits
This commit is contained in:
@@ -1006,7 +1006,8 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ActivityStream
|
model = ActivityStream
|
||||||
fields = ('id', 'url', 'related', 'summary_fields', 'timestamp', 'operation', 'changes')
|
fields = ('id', 'url', 'related', 'summary_fields', 'timestamp', 'operation', 'changes',
|
||||||
|
'object1_id', 'object1_type', 'object2_id', 'object2_type', 'object_relationship_type')
|
||||||
|
|
||||||
def get_related(self, obj):
|
def get_related(self, obj):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
@@ -1015,10 +1016,10 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
if obj.user is not None:
|
if obj.user is not None:
|
||||||
rel['user'] = reverse('api:user_detail', args=(obj.user.pk,))
|
rel['user'] = reverse('api:user_detail', args=(obj.user.pk,))
|
||||||
obj1_resolution = camelcase_to_underscore(obj.object1_type.split(".")[-1])
|
obj1_resolution = camelcase_to_underscore(obj.object1_type.split(".")[-1])
|
||||||
rel['object_1'] = reverse('api:' + obj1_resolution + '_detail', args=(obj.object1_id,))
|
rel['object1'] = reverse('api:' + obj1_resolution + '_detail', args=(obj.object1_id,))
|
||||||
if obj.operation in ('associate', 'disassociate'):
|
if obj.operation in ('associate', 'disassociate'):
|
||||||
obj2_resolution = camelcase_to_underscore(obj.object2_type.split(".")[-1])
|
obj2_resolution = camelcase_to_underscore(obj.object2_type.split(".")[-1])
|
||||||
rel['object_2'] = reverse('api:' + obj2_resolution + '_detail', args=(obj.object2_id,))
|
rel['object2'] = reverse('api:' + obj2_resolution + '_detail', args=(obj.object2_id,))
|
||||||
return rel
|
return rel
|
||||||
|
|
||||||
def get_summary_fields(self, obj):
|
def get_summary_fields(self, obj):
|
||||||
@@ -1026,14 +1027,24 @@ class ActivityStreamSerializer(BaseSerializer):
|
|||||||
return {}
|
return {}
|
||||||
d = super(ActivityStreamSerializer, self).get_summary_fields(obj)
|
d = super(ActivityStreamSerializer, self).get_summary_fields(obj)
|
||||||
try:
|
try:
|
||||||
|
short_obj_type = obj.object1_type.split(".")[-1]
|
||||||
|
under_short_obj_type = camelcase_to_underscore(short_obj_type)
|
||||||
obj1 = eval(obj.object1_type + ".objects.get(id=" + str(obj.object1_id) + ")")
|
obj1 = eval(obj.object1_type + ".objects.get(id=" + str(obj.object1_id) + ")")
|
||||||
d['object1'] = {'name': obj1.name, 'description': obj1.description}
|
d['object1'] = {'name': obj1.name, 'description': obj1.description,
|
||||||
|
'base': under_short_obj_type, 'id': obj.object1_id}
|
||||||
|
if under_short_obj_type == "host" or under_short_obj_type == "group":
|
||||||
|
d['inventory'] = {'name': obj1.inventory.name, 'id': obj1.inventory.id}
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Error getting object 1 summary: " + str(e))
|
logger.error("Error getting object 1 summary: " + str(e))
|
||||||
try:
|
try:
|
||||||
|
short_obj_type = obj.object2_type.split(".")[-1]
|
||||||
|
under_short_obj_type = camelcase_to_underscore(short_obj_type)
|
||||||
if obj.operation in ('associate', 'disassociate'):
|
if obj.operation in ('associate', 'disassociate'):
|
||||||
obj2 = eval(obj.object1_type + ".objects.get(id=" + str(obj.object2_id) + ")")
|
obj2 = eval(obj.object2_type + ".objects.get(id=" + str(obj.object2_id) + ")")
|
||||||
d['object2'] = {'name': obj2.name, 'description': obj2.description}
|
d['object2'] = {'name': obj2.name, 'description': obj2.description,
|
||||||
|
'base': under_short_obj_type, 'id': obj.object2_id}
|
||||||
|
if under_short_obj_type == "host" or under_short_obj_type == "group":
|
||||||
|
d['inventory'] = {'name': obj2.inventory.name, 'id': obj2.inventory.id}
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Error getting object 2 summary: " + str(e))
|
logger.error("Error getting object 2 summary: " + str(e))
|
||||||
return d
|
return d
|
||||||
|
|||||||
Reference in New Issue
Block a user