Add support for editing document comments

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-05-09 22:29:07 -04:00
parent cbd51c5f26
commit f73179a600
17 changed files with 348 additions and 43 deletions

View File

@@ -5,17 +5,19 @@ from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from mayan.apps.common.generics import (
SingleObjectCreateView, SingleObjectDeleteView, SingleObjectListView
SingleObjectCreateView, SingleObjectDeleteView, SingleObjectDetailView,
SingleObjectEditView, SingleObjectListView
)
from mayan.apps.common.mixins import ExternalObjectMixin
from mayan.apps.documents.models import Document
from .forms import DocumentCommentDetailForm
from .icons import icon_comments_for_document
from .links import link_comment_add
from .models import Comment
from .permissions import (
permission_document_comment_create, permission_document_comment_delete,
permission_document_comment_view
permission_document_comment_edit, permission_document_comment_view
)
@@ -24,7 +26,6 @@ class DocumentCommentCreateView(ExternalObjectMixin, SingleObjectCreateView):
external_object_permission = permission_document_comment_create
external_object_pk_url_kwarg = 'pk'
fields = ('comment',)
model = Comment
def get_extra_context(self):
return {
@@ -44,6 +45,9 @@ class DocumentCommentCreateView(ExternalObjectMixin, SingleObjectCreateView):
}
)
def get_queryset(self):
return self.external_object.comments.all()
def get_save_extra_data(self):
return {
'_user': self.request.user,
@@ -60,7 +64,9 @@ class DocumentCommentDeleteView(SingleObjectDeleteView):
def get_extra_context(self):
return {
'object': self.object.document,
'comment': self.object,
'document': self.object.document,
'navigation_object_list': ('document', 'comment'),
'title': _('Delete comment: %s?') % self.object,
}
@@ -72,6 +78,46 @@ class DocumentCommentDeleteView(SingleObjectDeleteView):
)
class DocumentCommentDetailView(SingleObjectDetailView):
form_class = DocumentCommentDetailForm
model = Comment
pk_url_kwarg = 'pk'
object_permission = permission_document_comment_view
def get_extra_context(self):
return {
'comment': self.object,
'document': self.object.document,
'navigation_object_list': ('document', 'comment'),
'title': _('Details for comment: %s?') % self.object,
}
class DocumentCommentEditView(SingleObjectEditView):
fields = ('comment',)
model = Comment
pk_url_kwarg = 'pk'
object_permission = permission_document_comment_edit
def get_save_extra_data(self):
return {'_user': self.request.user}
def get_extra_context(self):
return {
'comment': self.object,
'document': self.object.document,
'navigation_object_list': ('document', 'comment'),
'title': _('Edit comment: %s?') % self.object,
}
def get_post_action_redirect(self):
return reverse(
viewname='comments:comments_for_document', kwargs={
'pk': self.object.document.pk
}
)
class DocumentCommentListView(ExternalObjectMixin, SingleObjectListView):
external_object_class = Document
external_object_permission = permission_document_comment_view