Add tag attach and tag remove events.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
- Remove the view to submit all document for OCR.
|
- Remove the view to submit all document for OCR.
|
||||||
- When changing document types, don't delete the old metadata that is
|
- When changing document types, don't delete the old metadata that is
|
||||||
also found in the new document type. GitLab issue #421.
|
also found in the new document type. GitLab issue #421.
|
||||||
|
- Add tag attach and tag remove events.
|
||||||
|
|
||||||
2.6.4 (2017-07-26)
|
2.6.4 (2017-07-26)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class TagsApp(MayanAppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
super(TagsApp, self).ready()
|
super(TagsApp, self).ready()
|
||||||
|
from actstream import registry
|
||||||
|
|
||||||
Document = apps.get_model(
|
Document = apps.get_model(
|
||||||
app_label='documents', model_name='Document'
|
app_label='documents', model_name='Document'
|
||||||
@@ -143,3 +144,4 @@ class TagsApp(MayanAppConfig):
|
|||||||
'tags:single_document_multiple_tag_remove'
|
'tags:single_document_multiple_tag_remove'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
registry.register(Tag)
|
||||||
|
|||||||
14
mayan/apps/tags/events.py
Normal file
14
mayan/apps/tags/events.py
Normal 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')
|
||||||
|
)
|
||||||
@@ -11,6 +11,8 @@ from acls.models import AccessControlList
|
|||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
from documents.permissions import permission_document_view
|
from documents.permissions import permission_document_view
|
||||||
|
|
||||||
|
from .events import event_tag_attach, event_tag_remove
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
@@ -33,8 +35,11 @@ class Tag(models.Model):
|
|||||||
verbose_name = _('Tag')
|
verbose_name = _('Tag')
|
||||||
verbose_name_plural = _('Tags')
|
verbose_name_plural = _('Tags')
|
||||||
|
|
||||||
def attach_to(self, document):
|
def attach_to(self, document, user=None):
|
||||||
self.documents.add(document)
|
self.documents.add(document)
|
||||||
|
event_tag_attach.commit(
|
||||||
|
action_object=self, actor=user, target=document
|
||||||
|
)
|
||||||
|
|
||||||
def get_document_count(self, user):
|
def get_document_count(self, user):
|
||||||
queryset = AccessControlList.objects.filter_by_access(
|
queryset = AccessControlList.objects.filter_by_access(
|
||||||
@@ -43,8 +48,11 @@ class Tag(models.Model):
|
|||||||
|
|
||||||
return queryset.count()
|
return queryset.count()
|
||||||
|
|
||||||
def remove_from(self, document):
|
def remove_from(self, document, user=None):
|
||||||
self.documents.remove(document)
|
self.documents.remove(document)
|
||||||
|
event_tag_remove.commit(
|
||||||
|
action_object=self, actor=user, target=document
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentTag(Tag):
|
class DocumentTag(Tag):
|
||||||
|
|||||||
Reference in New Issue
Block a user