mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Make sure we show relative object information in the api
This commit is contained in:
@@ -12,7 +12,7 @@ from django.dispatch import receiver
|
||||
|
||||
# AWX
|
||||
from awx.main.models import *
|
||||
from awx.main.utils import model_instance_diff
|
||||
from awx.main.utils import model_instance_diff, model_to_dict
|
||||
|
||||
__all__ = []
|
||||
|
||||
@@ -178,7 +178,8 @@ def activity_stream_create(sender, instance, created, **kwargs):
|
||||
activity_entry = ActivityStream(
|
||||
operation='create',
|
||||
object1_id=instance.id,
|
||||
object1_type=str(instance.__class__))
|
||||
object1_type=instance.__class__.__module__ + "." + instance.__class__.__name__,
|
||||
changes=json.dumps(model_to_dict(instance)))
|
||||
activity_entry.save()
|
||||
|
||||
def activity_stream_update(sender, instance, **kwargs):
|
||||
@@ -192,7 +193,7 @@ def activity_stream_update(sender, instance, **kwargs):
|
||||
activity_entry = ActivityStream(
|
||||
operation='update',
|
||||
object1_id=instance.id,
|
||||
object1_type=str(instance.__class__),
|
||||
object1_type=instance.__class__.__module__ + "." + instance.__class__.__name__,
|
||||
changes=json.dumps(changes))
|
||||
activity_entry.save()
|
||||
|
||||
@@ -201,7 +202,7 @@ def activity_stream_delete(sender, instance, **kwargs):
|
||||
activity_entry = ActivityStream(
|
||||
operation='delete',
|
||||
object1_id=instance.id,
|
||||
object1_type=str(instance.__class__))
|
||||
object1_type=instance.__class__.__module__ + "." + instance.__class__.__name__)
|
||||
activity_entry.save()
|
||||
|
||||
def activity_stream_associate(sender, instance, **kwargs):
|
||||
@@ -214,15 +215,15 @@ def activity_stream_associate(sender, instance, **kwargs):
|
||||
return
|
||||
obj1 = instance
|
||||
obj1_id = obj1.id
|
||||
obj_rel = str(sender)
|
||||
obj_rel = sender.__module__ + "." + sender.__name__
|
||||
for entity_acted in kwargs['pk_set']:
|
||||
obj2 = kwargs['model']
|
||||
obj2_id = entity_acted
|
||||
activity_entry = ActivityStream(
|
||||
operation=action,
|
||||
object1_id=obj1_id,
|
||||
object1_type=str(obj1.__class__),
|
||||
object1_type=obj1.__class__.__module__ + "." + obj1.__class__.__name__,
|
||||
object2_id=obj2_id,
|
||||
object2_type=str(obj2.__class__),
|
||||
object2_type=obj2.__module__ + "." + obj2.__name__,
|
||||
object_relationship_type=obj_rel)
|
||||
activity_entry.save()
|
||||
|
||||
@@ -255,3 +255,12 @@ def model_instance_diff(old, new):
|
||||
diff = None
|
||||
|
||||
return diff
|
||||
|
||||
def model_to_dict(obj):
|
||||
"""
|
||||
Serialize a model instance to a dictionary as best as possible
|
||||
"""
|
||||
attr_d = {}
|
||||
for field in obj._meta.fields:
|
||||
attr_d[field.name] = str(getattr(obj, field.name, None))
|
||||
return attr_d
|
||||
|
||||
Reference in New Issue
Block a user