Files
mayan-edms/mayan/apps/documents/search.py
Roberto Rosario 0699ad0556 Add support for new document page structure
Documents now have their own dedicated DocumentPage
submodel. The old DocumentPage is now called DocumentVersionPage.
This allows mappings between document pages and document version
pages, allowing renumbering, appending pages.
DocumentPages have a content_object to map them to any other
object. For now they only map to DocumentVersionPages.
New option added to the version upload form to append the
pages of the new version.
A new view was added to just append new pages with wraps the
new document version upload form and hides the append pages
checkbox set to True.
Add a new action, reset_pages to reset the pages of the
document to those of the latest version.

Missing: appending tests, checks for proper content_object in OCR and
document parsing.

Author: Roberto Rosario <roberto.rosario@mayan-edms.com>
Date:   Thu Oct 11 12:00:25 2019 -0400
2019-10-10 11:55:42 -04:00

106 lines
3.5 KiB
Python

from __future__ import absolute_import, unicode_literals
from django.apps import apps
from django.db import connection
from django.utils.translation import ugettext_lazy as _
from mayan.apps.common.literals import LIST_MODE_CHOICE_ITEM
from mayan.apps.dynamic_search.classes import SearchModel
from .permissions import permission_document_view
def transformation_format_uuid(term_string):
if connection.vendor in ('mysql', 'sqlite'):
return term_string.replace('-', '')
else:
return term_string
def get_queryset_document_page_search_queryset():
# Ignore documents in trash can
DocumentPage = apps.get_model(
app_label='documents', model_name='DocumentPage'
)
return DocumentPage.objects.filter(document__in_trash=False)
def get_queryset_document_version_page_search_queryset():
# Ignore documents in trash can
DocumentVersionPage = apps.get_model(
app_label='documents', model_name='DocumentVersionPage'
)
return DocumentVersionPage.objects.filter(document_version__document__in_trash=False)
document_search = SearchModel(
app_label='documents', list_mode=LIST_MODE_CHOICE_ITEM,
model_name='Document', permission=permission_document_view,
serializer_path='mayan.apps.documents.serializers.DocumentSerializer'
)
document_search.add_model_field(
field='document_type__label', label=_('Document type')
)
document_search.add_model_field(
field='versions__mimetype', label=_('MIME type')
)
document_search.add_model_field(field='label', label=_('Label'))
document_search.add_model_field(field='description', label=_('Description'))
document_search.add_model_field(
field='uuid', label=_('UUID'),
transformation_function=transformation_format_uuid
)
document_search.add_model_field(
field='versions__checksum', label=_('Checksum')
)
document_page_search = SearchModel(
app_label='documents', list_mode=LIST_MODE_CHOICE_ITEM,
model_name='DocumentPage', permission=permission_document_view,
queryset=get_queryset_document_page_search_queryset,
serializer_path='mayan.apps.documents.serializers.DocumentPageSerializer'
)
document_version_page_search = SearchModel(
app_label='documents', list_mode=LIST_MODE_CHOICE_ITEM,
model_name='DocumentVersionPage', permission=permission_document_view,
queryset=get_queryset_document_version_page_search_queryset,
serializer_path='mayan.apps.documents.serializers.DocumentVersionPageSerializer'
)
document_page_search.add_model_field(
field='document__document_type__label',
label=_('Document type')
)
document_page_search.add_model_field(
field='document__versions__mimetype',
label=_('MIME type')
)
document_page_search.add_model_field(
field='document__label', label=_('Label')
)
document_page_search.add_model_field(
field='document__description', label=_('Description')
)
document_page_search.add_model_field(
field='document__versions__checksum', label=_('Checksum')
)
document_version_page_search.add_model_field(
field='document_version__document__document_type__label',
label=_('Document type')
)
document_version_page_search.add_model_field(
field='document_version__document__versions__mimetype',
label=_('MIME type')
)
document_version_page_search.add_model_field(
field='document_version__document__label', label=_('Label')
)
document_version_page_search.add_model_field(
field='document_version__document__description', label=_('Description')
)
document_version_page_search.add_model_field(
field='document_version__checksum', label=_('Checksum')
)