Split duplicated document views
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -12,14 +12,6 @@ from .api_views import (
|
||||
APIDocumentVersionPageListView, APIDocumentVersionView,
|
||||
APIRecentDocumentListView
|
||||
)
|
||||
from .views.document_views import (
|
||||
DocumentDocumentTypeEditView, DocumentDownloadFormView,
|
||||
DocumentDownloadView, DocumentDuplicatesListView, DocumentEditView,
|
||||
DocumentListView, DocumentPreviewView, DocumentPrint,
|
||||
DocumentTransformationsClearView, DocumentTransformationsCloneView,
|
||||
DocumentUpdatePageCountView, DocumentView, DuplicatedDocumentListView,
|
||||
RecentAccessDocumentListView, RecentAddedDocumentListView
|
||||
)
|
||||
from .views.document_page_views import (
|
||||
DocumentPageDisable, DocumentPageEnable, DocumentPageListView,
|
||||
DocumentPageNavigationFirst, DocumentPageNavigationLast,
|
||||
@@ -28,10 +20,6 @@ from .views.document_page_views import (
|
||||
DocumentPageView, DocumentPageViewResetView, DocumentPageZoomInView,
|
||||
DocumentPageZoomOutView
|
||||
)
|
||||
from .views.document_version_views import (
|
||||
DocumentVersionDownloadFormView, DocumentVersionDownloadView,
|
||||
DocumentVersionListView, DocumentVersionRevertView, DocumentVersionView,
|
||||
)
|
||||
from .views.document_type_views import (
|
||||
DocumentTypeCreateView, DocumentTypeDeleteView,
|
||||
DocumentTypeDeletionPoliciesEditView, DocumentTypeDocumentListView,
|
||||
@@ -39,6 +27,20 @@ from .views.document_type_views import (
|
||||
DocumentTypeFilenameDeleteView, DocumentTypeFilenameEditView,
|
||||
DocumentTypeFilenameListView, DocumentTypeListView
|
||||
)
|
||||
from .views.document_version_views import (
|
||||
DocumentVersionDownloadFormView, DocumentVersionDownloadView,
|
||||
DocumentVersionListView, DocumentVersionRevertView, DocumentVersionView,
|
||||
)
|
||||
from .views.document_views import (
|
||||
DocumentDocumentTypeEditView, DocumentDownloadFormView,
|
||||
DocumentDownloadView, DocumentEditView, DocumentListView,
|
||||
DocumentPreviewView, DocumentPrint, DocumentTransformationsClearView,
|
||||
DocumentTransformationsCloneView, DocumentUpdatePageCountView,
|
||||
DocumentView, RecentAccessDocumentListView, RecentAddedDocumentListView
|
||||
)
|
||||
from .views.duplicated_document_views import (
|
||||
DocumentDuplicatesListView, DuplicatedDocumentListView
|
||||
)
|
||||
from .views.favorite_document_views import (
|
||||
FavoriteAddView, FavoriteDocumentListView, FavoriteRemoveView
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ from .document_page_views import * # NOQA
|
||||
from .document_type_views import * # NOQA
|
||||
from .document_version_views import * # NOQA
|
||||
from .document_views import * # NOQA
|
||||
from .duplicated_document_views import * # NOQA
|
||||
from .favorite_document_views import * # NOQA
|
||||
from .misc_views import * # NOQA
|
||||
from .trashed_document_views import * # NOQA
|
||||
|
||||
@@ -32,10 +32,10 @@ from ..forms import (
|
||||
)
|
||||
from ..icons import (
|
||||
icon_document_list, icon_document_list_recent_access,
|
||||
icon_recent_added_document_list, icon_duplicated_document_list
|
||||
icon_recent_added_document_list
|
||||
)
|
||||
from ..literals import PAGE_RANGE_RANGE, DEFAULT_ZIP_FILENAME
|
||||
from ..models import Document, DuplicatedDocument, RecentDocument
|
||||
from ..models import Document, RecentDocument
|
||||
from ..permissions import (
|
||||
permission_document_download, permission_document_print,
|
||||
permission_document_properties_edit, permission_document_tools,
|
||||
@@ -48,12 +48,11 @@ from ..tasks import task_update_page_count
|
||||
from ..utils import parse_range
|
||||
|
||||
__all__ = (
|
||||
'DocumentListView', 'DocumentDocumentTypeEditView',
|
||||
'DocumentDuplicatesListView', 'DocumentEditView', 'DocumentPreviewView',
|
||||
'DocumentView', 'DocumentDownloadFormView', 'DocumentDownloadView',
|
||||
'DocumentUpdatePageCountView', 'DocumentTransformationsClearView',
|
||||
'DocumentTransformationsCloneView', 'DocumentPrint',
|
||||
'DuplicatedDocumentListView', 'RecentAccessDocumentListView',
|
||||
'DocumentListView', 'DocumentDocumentTypeEditView', 'DocumentEditView',
|
||||
'DocumentPreviewView', 'DocumentView', 'DocumentDownloadFormView',
|
||||
'DocumentDownloadView', 'DocumentUpdatePageCountView',
|
||||
'DocumentTransformationsClearView', 'DocumentTransformationsCloneView',
|
||||
'DocumentPrint', 'RecentAccessDocumentListView',
|
||||
'RecentAddedDocumentListView'
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -322,47 +321,6 @@ class DocumentDownloadView(SingleObjectDownloadView):
|
||||
return item.label
|
||||
|
||||
|
||||
class DocumentDuplicatesListView(DocumentListView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
AccessControlList.objects.check_access(
|
||||
obj=self.get_document(), permissions=(permission_document_view,),
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
return super(
|
||||
DocumentDuplicatesListView, self
|
||||
).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_document(self):
|
||||
return get_object_or_404(klass=Document, pk=self.kwargs['pk'])
|
||||
|
||||
def get_extra_context(self):
|
||||
context = super(DocumentDuplicatesListView, self).get_extra_context()
|
||||
context.update(
|
||||
{
|
||||
'no_results_icon': icon_duplicated_document_list,
|
||||
'no_results_text': _(
|
||||
'Only exact copies of this document will be shown in the '
|
||||
'this list.'
|
||||
),
|
||||
'no_results_title': _(
|
||||
'There are no duplicates for this document'
|
||||
),
|
||||
'object': self.get_document(),
|
||||
'title': _('Duplicates for document: %s') % self.get_document(),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_source_queryset(self):
|
||||
try:
|
||||
return DuplicatedDocument.objects.get(
|
||||
document=self.get_document()
|
||||
).documents.all()
|
||||
except DuplicatedDocument.DoesNotExist:
|
||||
return Document.objects.none()
|
||||
|
||||
|
||||
class DocumentEditView(SingleObjectEditView):
|
||||
form_class = DocumentForm
|
||||
model = Document
|
||||
@@ -675,31 +633,6 @@ class DocumentPrint(FormView):
|
||||
return (self.template_name,)
|
||||
|
||||
|
||||
class DuplicatedDocumentListView(DocumentListView):
|
||||
def get_document_queryset(self):
|
||||
return DuplicatedDocument.objects.get_duplicated_documents()
|
||||
|
||||
def get_extra_context(self):
|
||||
context = super(DuplicatedDocumentListView, self).get_extra_context()
|
||||
context.update(
|
||||
{
|
||||
'no_results_icon': icon_duplicated_document_list,
|
||||
'no_results_text': _(
|
||||
'Duplicates are documents that are composed of the exact '
|
||||
'same file, down to the last byte. Files that have the '
|
||||
'same text or OCR but are not identical or were saved '
|
||||
'using a different file format will not appear as '
|
||||
'duplicates.'
|
||||
),
|
||||
'no_results_title': _(
|
||||
'There are no duplicated documents'
|
||||
),
|
||||
'title': _('Duplicated documents')
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
class RecentAccessDocumentListView(DocumentListView):
|
||||
def get_document_queryset(self):
|
||||
return RecentDocument.objects.get_for_user(user=self.request.user)
|
||||
|
||||
94
mayan/apps/documents/views/duplicated_document_views.py
Normal file
94
mayan/apps/documents/views/duplicated_document_views.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from mayan.apps.acls.models import AccessControlList
|
||||
from mayan.apps.common.generics import (
|
||||
FormView, MultipleObjectConfirmActionView, MultipleObjectFormActionView,
|
||||
SingleObjectDetailView, SingleObjectListView
|
||||
)
|
||||
|
||||
from ..events import event_document_view
|
||||
from ..icons import icon_document_list, icon_duplicated_document_list
|
||||
from ..models import Document, DuplicatedDocument
|
||||
from ..permissions import permission_document_view
|
||||
|
||||
from .document_views import DocumentListView
|
||||
|
||||
__all__ = ('DocumentDuplicatesListView', 'DuplicatedDocumentListView')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DocumentDuplicatesListView(DocumentListView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
AccessControlList.objects.check_access(
|
||||
obj=self.get_document(), permissions=(permission_document_view,),
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
return super(
|
||||
DocumentDuplicatesListView, self
|
||||
).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_document(self):
|
||||
return get_object_or_404(klass=Document, pk=self.kwargs['pk'])
|
||||
|
||||
def get_extra_context(self):
|
||||
context = super(DocumentDuplicatesListView, self).get_extra_context()
|
||||
context.update(
|
||||
{
|
||||
'no_results_icon': icon_duplicated_document_list,
|
||||
'no_results_text': _(
|
||||
'Only exact copies of this document will be shown in the '
|
||||
'this list.'
|
||||
),
|
||||
'no_results_title': _(
|
||||
'There are no duplicates for this document'
|
||||
),
|
||||
'object': self.get_document(),
|
||||
'title': _('Duplicates for document: %s') % self.get_document(),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
def get_source_queryset(self):
|
||||
try:
|
||||
return DuplicatedDocument.objects.get(
|
||||
document=self.get_document()
|
||||
).documents.all()
|
||||
except DuplicatedDocument.DoesNotExist:
|
||||
return Document.objects.none()
|
||||
|
||||
|
||||
class DuplicatedDocumentListView(DocumentListView):
|
||||
def get_document_queryset(self):
|
||||
return DuplicatedDocument.objects.get_duplicated_documents()
|
||||
|
||||
def get_extra_context(self):
|
||||
context = super(DuplicatedDocumentListView, self).get_extra_context()
|
||||
context.update(
|
||||
{
|
||||
'no_results_icon': icon_duplicated_document_list,
|
||||
'no_results_text': _(
|
||||
'Duplicates are documents that are composed of the exact '
|
||||
'same file, down to the last byte. Files that have the '
|
||||
'same text or OCR but are not identical or were saved '
|
||||
'using a different file format will not appear as '
|
||||
'duplicates.'
|
||||
),
|
||||
'no_results_title': _(
|
||||
'There are no duplicated documents'
|
||||
),
|
||||
'title': _('Duplicated documents')
|
||||
}
|
||||
)
|
||||
return context
|
||||
Reference in New Issue
Block a user