diff --git a/HISTORY.rst b/HISTORY.rst index b833082cde..b3f8d64979 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -34,6 +34,7 @@ - Remove the view to submit all document for OCR. - When changing document types, don't delete the old metadata that is also found in the new document type. GitLab issue #421. +- Add tag attach and tag remove events. 2.6.4 (2017-07-26) ================== diff --git a/mayan/apps/tags/apps.py b/mayan/apps/tags/apps.py index 94dd256fef..14a780aef5 100644 --- a/mayan/apps/tags/apps.py +++ b/mayan/apps/tags/apps.py @@ -36,6 +36,7 @@ class TagsApp(MayanAppConfig): def ready(self): super(TagsApp, self).ready() + from actstream import registry Document = apps.get_model( app_label='documents', model_name='Document' @@ -143,3 +144,4 @@ class TagsApp(MayanAppConfig): 'tags:single_document_multiple_tag_remove' ) ) + registry.register(Tag) diff --git a/mayan/apps/tags/events.py b/mayan/apps/tags/events.py new file mode 100644 index 0000000000..e5063aee2c --- /dev/null +++ b/mayan/apps/tags/events.py @@ -0,0 +1,14 @@ +from __future__ import absolute_import, unicode_literals + +from django.utils.translation import ugettext_lazy as _ + +from events.classes import Event + +event_tag_attach = Event( + name='tag_attach', + label=_('Tag attached to document') +) +event_tag_remove = Event( + name='tag_remove', + label=_('Tag removed from document') +) diff --git a/mayan/apps/tags/models.py b/mayan/apps/tags/models.py index 67534c0aad..db026e53c8 100644 --- a/mayan/apps/tags/models.py +++ b/mayan/apps/tags/models.py @@ -11,6 +11,8 @@ from acls.models import AccessControlList from documents.models import Document from documents.permissions import permission_document_view +from .events import event_tag_attach, event_tag_remove + @python_2_unicode_compatible class Tag(models.Model): @@ -33,8 +35,11 @@ class Tag(models.Model): verbose_name = _('Tag') verbose_name_plural = _('Tags') - def attach_to(self, document): + def attach_to(self, document, user=None): self.documents.add(document) + event_tag_attach.commit( + action_object=self, actor=user, target=document + ) def get_document_count(self, user): queryset = AccessControlList.objects.filter_by_access( @@ -43,8 +48,11 @@ class Tag(models.Model): return queryset.count() - def remove_from(self, document): + def remove_from(self, document, user=None): self.documents.remove(document) + event_tag_remove.commit( + action_object=self, actor=user, target=document + ) class DocumentTag(Tag):