Add document attach and remove methods to Tag

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-02-15 04:24:25 -04:00
parent bb7bbb299b
commit 1c3595c66e

View File

@@ -44,15 +44,26 @@ class Tag(models.Model):
def __str__(self):
return self.label
def attach_to(self, document, user=None):
def documents_attach(self, queryset, _user=None):
"""
Attach a tag to a document and commit the corresponding event.
"""
with transaction.atomic():
for document in documents:
for document in queryset:
self.documents.add(document)
event_tag_attach.commit(
action_object=self, actor=user, target=document
action_object=self, actor=_user, target=document
)
def documents_remove(self, queryset, _user=None):
"""
Remove a tag from a document and commit the corresponding event.
"""
with transaction.atomic():
for document in queryset:
self.documents.remove(document)
event_tag_remove.commit(
action_object=self, actor=_user, target=document
)
def get_absolute_url(self):
@@ -74,17 +85,6 @@ class Tag(models.Model):
def get_document_count(self, user):
return self.get_documents(user=user).count()
def remove_from(self, documents, _user=None):
"""
Remove a tag from a document and commit the corresponding event.
"""
with transaction.atomic():
for document in documents:
self.documents.remove(document)
event_tag_remove.commit(
action_object=self, actor=user, target=document
)
def save(self, *args, **kwargs):
user = kwargs.pop('_user', None)
created = not self.pk