Add event logging document comment app.
This commit is contained in:
14
mayan/apps/document_comments/events.py
Normal file
14
mayan/apps/document_comments/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_document_comment_create = Event(
|
||||||
|
name='document_comment_create',
|
||||||
|
label=_('Document comment created')
|
||||||
|
)
|
||||||
|
event_document_comment_delete = Event(
|
||||||
|
name='document_comment_delete',
|
||||||
|
label=_('Document comment deleted')
|
||||||
|
)
|
||||||
@@ -7,6 +7,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
|
|
||||||
|
from .events import event_document_comment_create, event_document_comment_delete
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Comment(models.Model):
|
class Comment(models.Model):
|
||||||
@@ -28,8 +30,35 @@ class Comment(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.comment
|
return self.comment
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
user = kwargs.pop('_user', None) or self.user
|
||||||
|
is_new = not self.pk
|
||||||
|
super(Comment, self).save(*args, **kwargs)
|
||||||
|
if is_new:
|
||||||
|
if user:
|
||||||
|
event_document_comment_create.commit(
|
||||||
|
actor=user, target=self.document
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
event_document_comment_create.commit(target=self.document)
|
||||||
|
|
||||||
|
def delete(self, *args, **kwargs):
|
||||||
|
user = kwargs.pop('_user', None)
|
||||||
|
super(Comment, self).delete(*args, **kwargs)
|
||||||
|
if user:
|
||||||
|
event_document_comment_delete.commit(actor=user, target=self.document)
|
||||||
|
else:
|
||||||
|
event_document_comment_delete.commit(target=self.document)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
get_latest_by = 'submit_date'
|
get_latest_by = 'submit_date'
|
||||||
ordering = ('-submit_date',)
|
ordering = ('-submit_date',)
|
||||||
verbose_name = _('Comment')
|
verbose_name = _('Comment')
|
||||||
verbose_name_plural = _('Comments')
|
verbose_name_plural = _('Comments')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class DocumentCommentCreateView(SingleObjectCreateView):
|
|||||||
|
|
||||||
def get_instance_extra_data(self):
|
def get_instance_extra_data(self):
|
||||||
return {
|
return {
|
||||||
'document': self.get_document(), 'user': self.request.user
|
'document': self.get_document(), 'user': self.request.user,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_post_action_redirect(self):
|
def get_post_action_redirect(self):
|
||||||
@@ -75,6 +75,9 @@ class DocumentCommentDeleteView(SingleObjectDeleteView):
|
|||||||
|
|
||||||
return super(DocumentCommentDeleteView, self).dispatch(request, *args, **kwargs)
|
return super(DocumentCommentDeleteView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_delete_extra_data(self):
|
||||||
|
return {'_user': self.request.user}
|
||||||
|
|
||||||
def get_extra_context(self):
|
def get_extra_context(self):
|
||||||
return {
|
return {
|
||||||
'object': self.get_object().document,
|
'object': self.get_object().document,
|
||||||
|
|||||||
Reference in New Issue
Block a user