Add tag attach and tag remove events.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-08-25 00:34:43 -04:00
parent 257c5d9036
commit fd7ebff179
4 changed files with 27 additions and 2 deletions

View File

@@ -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)
==================

View File

@@ -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)

14
mayan/apps/tags/events.py Normal file
View File

@@ -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')
)

View File

@@ -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):