diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index e25752e403..05d38c027b 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -6,6 +6,7 @@ from awx.main.models.organization import * from awx.main.models.projects import * from awx.main.models.inventory import * from awx.main.models.jobs import * +from awx.main.registrar import activity_stream_registrar # Monkeypatch Django serializer to ignore django-taggit fields (which break # the dumpdata command; see https://github.com/alex/django-taggit/issues/155). diff --git a/awx/main/models/base.py b/awx/main/models/base.py index bddcb4be1a..53fc46326d 100644 --- a/awx/main/models/base.py +++ b/awx/main/models/base.py @@ -346,7 +346,7 @@ class ActivityStream(models.Model): ('disaassociate', _("Entity was Disassociated with another Entity")) ] - user = models.ForeignKey('auth.User', null=True, on_delete=SET_NULL) + user = models.ForeignKey('auth.User', null=True, on_delete=models.SET_NULL) operation = models.CharField(max_length=9, choices=OPERATION_CHOICES) timestamp = models.DateTimeField(auto_now_add=True) changes = models.TextField(blank=True) diff --git a/awx/main/registrar.py b/awx/main/registrar.py index f5c631a053..f4a6b64484 100644 --- a/awx/main/registrar.py +++ b/awx/main/registrar.py @@ -1,5 +1,5 @@ from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed -from signals import activity_stream_create, activity_stream_update, activity_stream_delete +from signals import activity_stream_create, activity_stream_update, activity_stream_delete, activity_stream_associate class ActivityStreamRegistrar(object): @@ -10,25 +10,25 @@ class ActivityStreamRegistrar(object): #(receiver, sender=model, dispatch_uid=self._dispatch_uid(signal, model)) if model not in self.models: self.models.append(model) - post_save.connect(activity_stream_create, sender=model, dispatch_uid=self.__class__ + str(model) + "_create") - pre_save.connect(activity_stream_update, sender=model, dispatch_uid=self.__class__ + str(model) + "_update") - post_delete.connect(activity_stream_delete, sender=model, dispatch_uid=self.__class__ + str(model) + "_delete") + post_save.connect(activity_stream_create, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_create") + pre_save.connect(activity_stream_update, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_update") + post_delete.connect(activity_stream_delete, sender=model, dispatch_uid=str(self.__class__) + str(model) + "_delete") for m2mfield in model._meta.many_to_many: - m2m_attr = get_attr(model, m2mfield.name) + m2m_attr = getattr(model, m2mfield.name) m2m_changed.connect(activity_stream_associate, sender=m2m_attr.through, - dispatch_uid=self.__class__ + str(m2m_attr.through) + "_associate") + dispatch_uid=str(self.__class__) + str(m2m_attr.through) + "_associate") def disconnect(self, model): if model in self.models: - post_save.disconnect(dispatch_uid=self.__class__ + str(model) + "_create") - pre_save.disconnect(dispatch_uid=self.__class__ + str(model) + "_update") - post_delete.disconnect(dispatch_uid=self.__class__ + str(model) + "_delete") + post_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_create") + pre_save.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_update") + post_delete.disconnect(dispatch_uid=str(self.__class__) + str(model) + "_delete") self.models.pop(model) for m2mfield in model._meta.many_to_many: - m2m_attr = get_attr(model, m2mfield.name) - m2m_changed.disconnect(dispatch_uid=self.__class__ + str(m2m_attr.through) + "_associate") + m2m_attr = getattr(model, m2mfield.name) + m2m_changed.disconnect(dispatch_uid=str(self.__class__) + str(m2m_attr.through) + "_associate") activity_stream_registrar = ActivityStreamRegistrar()