Files
mayan-edms/mayan/apps/documents/links.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

465 lines
19 KiB
Python

from __future__ import absolute_import, unicode_literals
from django.utils.translation import ugettext_lazy as _
from mayan.apps.converter.permissions import (
permission_transformation_delete, permission_transformation_edit
)
from mayan.apps.navigation.classes import Link
from .icons import (
icon_document_list_recent_access,
icon_recent_added_document_list, icon_document_page_navigation_first,
icon_document_page_navigation_last, icon_document_page_navigation_next,
icon_document_page_navigation_previous, icon_document_page_return,
icon_document_page_rotate_left, icon_document_page_rotate_right,
icon_document_page_zoom_in, icon_document_page_zoom_out,
icon_document_type_create, icon_document_type_delete,
icon_document_type_edit, icon_document_type_setup,
icon_duplicated_document_list, icon_duplicated_document_scan
)
from .permissions import (
permission_document_delete, permission_document_edit,
permission_document_download, permission_document_properties_edit,
permission_document_print, permission_document_restore,
permission_document_tools, permission_document_version_revert,
permission_document_view, permission_document_trash,
permission_document_type_create, permission_document_type_delete,
permission_document_type_edit, permission_document_type_view,
permission_empty_trash, permission_document_version_view
)
from .settings import setting_zoom_max_level, setting_zoom_min_level
def is_not_current_version(context):
# Use the 'object' key when the document version is an object in a list,
# such as when showing the version list view and use the 'resolved_object'
# when the document version is the context object, such as when showing the
# signatures list of a documern version. This can be fixed by updating
# the navigations app object resolution logic to use 'resolved_object' even
# for objects in a list.
document_version = context.get('object', context['resolved_object'])
return document_version.document.latest_version.timestamp != document_version.timestamp
def is_first_page(context):
return context['resolved_object'].siblings.first() == context['resolved_object']
def is_last_page(context):
return context['resolved_object'].siblings.last() == context['resolved_object']
def is_max_zoom(context):
return context['zoom'] >= setting_zoom_max_level.value
def is_min_zoom(context):
return context['zoom'] <= setting_zoom_min_level.value
def is_document_page_enabled(context):
return context['resolved_object'].enabled
def is_document_page_disabled(context):
return not context['resolved_object'].enabled
# Facet
link_document_preview = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_preview',
permissions=(permission_document_view,),
text=_('Preview'), view='documents:document_preview',
)
link_document_properties = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_properties',
permissions=(permission_document_view,),
text=_('Properties'), view='documents:document_properties',
)
link_document_version_list = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_list',
permissions=(permission_document_version_view,),
text=_('Versions'), view='documents:document_version_list',
)
link_document_pages = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_pages',
permissions=(permission_document_view,), text=_('Pages'),
view='documents:document_pages',
)
# Actions
link_document_clear_transformations = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_transformations_clear',
permissions=(permission_transformation_delete,),
text=_('Clear transformations'),
view='documents:document_clear_transformations',
)
link_document_clone_transformations = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_transformations_clone',
permissions=(permission_transformation_edit,),
text=_('Clone transformations'),
view='documents:document_clone_transformations',
)
link_document_delete = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_trashed_document_delete',
permissions=(permission_document_delete,),
tags='dangerous', text=_('Delete'), view='documents:document_delete',
)
link_document_list_favorites = Link(
icon_class_path='mayan.apps.documents.icons.icon_favorite_document_list',
text=_('Favorites'),
view='documents:document_list_favorites'
)
link_document_favorites_add = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_favorite_document_add',
permissions=(permission_document_view,), text=_('Add to favorites'),
view='documents:document_add_to_favorites',
)
link_document_favorites_remove = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_favorite_document_remove',
permissions=(permission_document_view,), text=_('Remove from favorites'),
view='documents:document_remove_from_favorites',
)
link_document_trash = Link(
args='resolved_object.id', permissions=(permission_document_trash,),
icon_class_path='mayan.apps.documents.icons.icon_document_trash_send',
tags='dangerous', text=_('Move to trash'),
view='documents:document_trash',
)
link_document_edit = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_edit',
permissions=(permission_document_properties_edit,),
text=_('Edit properties'), view='documents:document_edit',
)
link_document_document_type_edit = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_change',
permissions=(permission_document_properties_edit,), text=_('Change type'),
view='documents:document_document_type_edit',
)
link_document_download = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_download',
permissions=(permission_document_download,), text=_('Advanced download'),
view='documents:document_download_form',
)
link_document_print = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_print',
permissions=(permission_document_print,),
text=_('Print'), view='documents:document_print',
)
link_document_quick_download = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_quick_download',
permissions=(permission_document_download,), text=_('Quick download'),
view='documents:document_download',
)
link_document_pages_reset = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_pages_reset',
permissions=(permission_document_tools,),
text=_('Reset pages'),
view='documents:document_pages_reset'
)
link_document_restore = Link(
permissions=(permission_document_restore,),
icon_class_path='mayan.apps.documents.icons.icon_trashed_document_restore',
text=_('Restore'),
view='documents:document_restore', args='object.pk'
)
link_document_multiple_clear_transformations = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_transformations_clear',
permissions=(permission_transformation_delete,),
text=_('Clear transformations'),
view='documents:document_multiple_clear_transformations'
)
link_document_multiple_trash = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_trash_send',
tags='dangerous', text=_('Move to trash'),
view='documents:document_multiple_trash'
)
link_document_multiple_delete = Link(
icon_class_path='mayan.apps.documents.icons.icon_trashed_document_delete',
tags='dangerous', text=_('Delete'),
view='documents:document_multiple_delete'
)
link_document_multiple_favorites_add = Link(
text=_('Add to favorites'),
icon_class_path='mayan.apps.documents.icons.icon_favorite_document_add',
view='documents:document_multiple_add_to_favorites',
)
link_document_multiple_favorites_remove = Link(
text=_('Remove from favorites'),
icon_class_path='mayan.apps.documents.icons.icon_favorite_document_remove',
view='documents:document_multiple_remove_from_favorites',
)
link_document_multiple_document_type_edit = Link(
text=_('Change type'),
icon_class_path='mayan.apps.documents.icons.icon_document_type_change',
view='documents:document_multiple_document_type_edit'
)
link_document_multiple_download = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_download',
text=_('Advanced download'),
view='documents:document_multiple_download_form'
)
link_document_multiple_pages_reset = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_pages_reset',
text=_('Reset pages'),
view='documents:document_multiple_pages_reset'
)
link_document_multiple_restore = Link(
icon_class_path='mayan.apps.documents.icons.icon_trashed_document_restore',
text=_('Restore'), view='documents:document_multiple_restore'
)
# Versions
link_document_version_download = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_download',
permissions=(permission_document_download,), text=_('Download version'),
view='documents:document_version_download_form'
)
link_document_version_return_document = Link(
args='resolved_object.document.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_return_document',
permissions=(permission_document_view,), text=_('Document'),
view='documents:document_preview',
)
link_document_version_return_list = Link(
args='resolved_object.document.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_return_list',
permissions=(permission_document_version_view,), text=_('Versions'),
view='documents:document_version_list',
)
link_document_version_page_count_update = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_page_count_update',
permissions=(permission_document_tools,),
text=_('Update page count'),
view='documents:document_version_page_count_update'
)
link_document_version_multiple_page_count_update = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_version_page_count_update',
text=_('Update page count'),
view='documents:document_version_multiple_page_count_update'
)
link_document_version_view = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.documents.icons.icon_document_version_view',
permissions=(permission_document_version_view,),
text=_('Details'), view='documents:document_version_view'
)
# Views
link_document_list = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_list',
text=_('All documents'),
view='documents:document_list'
)
link_document_list_recent_access = Link(
icon_class=icon_document_list_recent_access, text=_('Recently accessed'),
view='documents:document_list_recent_access'
)
link_document_list_recent_added = Link(
icon_class=icon_recent_added_document_list, text=_('Recently added'),
view='documents:document_list_recent_added'
)
link_document_list_deleted = Link(
icon_class_path='mayan.apps.documents.icons.icon_trashed_document_list',
text=_('Trash can'), view='documents:document_list_deleted'
)
link_trash_can_empty = Link(
permissions=(permission_empty_trash,), text=_('Empty trash'),
view='documents:trash_can_empty'
)
# Document pages
link_document_page_disable = Link(
condition=is_document_page_enabled,
icon_class_path='mayan.apps.documents.icons.icon_document_page_disable',
kwargs={'pk': 'resolved_object.id'},
permissions=(permission_document_edit,), text=_('Disable page'),
view='documents:document_page_disable'
)
link_document_page_multiple_disable = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_page_disable',
text=_('Disable pages'),
view='documents:document_page_multiple_disable'
)
link_document_page_enable = Link(
condition=is_document_page_disabled,
icon_class_path='mayan.apps.documents.icons.icon_document_page_enable',
kwargs={'pk': 'resolved_object.id'},
permissions=(permission_document_edit,), text=_('Enable page'),
view='documents:document_page_enable'
)
link_document_page_multiple_enable = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_page_enable',
text=_('Enable pages'),
view='documents:document_page_multiple_enable'
)
link_document_page_navigation_first = Link(
args='resolved_object.pk', conditional_disable=is_first_page,
icon_class=icon_document_page_navigation_first,
keep_query=True, permissions=(permission_document_view,),
text=_('First page'), view='documents:document_page_navigation_first',
)
link_document_page_navigation_last = Link(
args='resolved_object.pk', conditional_disable=is_last_page,
icon_class=icon_document_page_navigation_last,
keep_query=True, text=_('Last page'),
permissions=(permission_document_view,),
view='documents:document_page_navigation_last',
)
link_document_page_navigation_previous = Link(
args='resolved_object.pk', conditional_disable=is_first_page,
icon_class=icon_document_page_navigation_previous,
keep_query=True, permissions=(permission_document_view,),
text=_('Previous page'),
view='documents:document_page_navigation_previous',
)
link_document_page_navigation_next = Link(
args='resolved_object.pk', conditional_disable=is_last_page,
icon_class=icon_document_page_navigation_next,
keep_query=True, text=_('Next page'),
permissions=(permission_document_view,),
view='documents:document_page_navigation_next',
)
link_document_page_return = Link(
args='resolved_object.document.pk', icon_class=icon_document_page_return,
permissions=(permission_document_view,), text=_('Document'),
view='documents:document_preview',
)
link_document_page_rotate_left = Link(
args='resolved_object.pk', icon_class=icon_document_page_rotate_left,
keep_query=True, permissions=(permission_document_view,),
text=_('Rotate left'), view='documents:document_page_rotate_left',
)
link_document_page_rotate_right = Link(
args='resolved_object.pk', icon_class=icon_document_page_rotate_right,
keep_query=True, permissions=(permission_document_view,),
text=_('Rotate right'), view='documents:document_page_rotate_right',
)
link_document_page_view = Link(
conditional_disable=is_document_page_disabled,
icon_class_path='mayan.apps.documents.icons.icon_document_page_view',
permissions=(permission_document_view,), text=_('Page image'),
view='documents:document_page_view', args='resolved_object.pk'
)
link_document_page_view_reset = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_page_view_reset',
permissions=(permission_document_view,), text=_('Reset view'),
view='documents:document_page_view_reset', args='resolved_object.pk'
)
link_document_page_zoom_in = Link(
args='resolved_object.pk', conditional_disable=is_max_zoom,
icon_class=icon_document_page_zoom_in, keep_query=True,
permissions=(permission_document_view,), text=_('Zoom in'),
view='documents:document_page_zoom_in',
)
link_document_page_zoom_out = Link(
args='resolved_object.pk', conditional_disable=is_min_zoom,
icon_class=icon_document_page_zoom_out, keep_query=True,
permissions=(permission_document_view,), text=_('Zoom out'),
view='documents:document_page_zoom_out',
)
# Document versions
link_document_version_revert = Link(
args='object.pk', condition=is_not_current_version,
icon_class_path='mayan.apps.documents.icons.icon_document_version_revert',
permissions=(permission_document_version_revert,), tags='dangerous',
text=_('Revert'), view='documents:document_version_revert',
)
# Document type related links
link_document_type_create = Link(
icon_class=icon_document_type_create,
permissions=(permission_document_type_create,),
text=_('Create document type'), view='documents:document_type_create'
)
link_document_type_delete = Link(
args='resolved_object.id', icon_class=icon_document_type_delete,
permissions=(permission_document_type_delete,), tags='dangerous',
text=_('Delete'), view='documents:document_type_delete',
)
link_document_type_policies = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_policies',
permissions=(permission_document_type_edit,),
text=_('Deletion policies'), view='documents:document_type_policies',
)
link_document_type_edit = Link(
args='resolved_object.id', icon_class=icon_document_type_edit,
permissions=(permission_document_type_edit,), text=_('Edit'),
view='documents:document_type_edit',
)
link_document_type_filename_create = Link(
args='document_type.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_filename_create',
permissions=(permission_document_type_edit,),
text=_('Add quick label to document type'),
view='documents:document_type_filename_create',
)
link_document_type_filename_delete = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_filename_delete',
permissions=(permission_document_type_edit,),
tags='dangerous', text=_('Delete'),
view='documents:document_type_filename_delete',
)
link_document_type_filename_edit = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_filename_edit',
permissions=(permission_document_type_edit,),
text=_('Edit'), view='documents:document_type_filename_edit',
)
link_document_type_filename_list = Link(
args='resolved_object.id',
icon_class_path='mayan.apps.documents.icons.icon_document_type_filename_list',
permissions=(permission_document_type_view,),
text=_('Quick labels'), view='documents:document_type_filename_list',
)
link_document_type_list = Link(
icon_class_path='mayan.apps.documents.icons.icon_document_type_list',
permissions=(permission_document_type_view,), text=_('Document types'),
view='documents:document_type_list'
)
link_document_type_setup = Link(
icon_class=icon_document_type_setup,
permissions=(permission_document_type_view,), text=_('Document types'),
view='documents:document_type_list'
)
link_duplicated_document_list = Link(
icon_class=icon_duplicated_document_list, text=_('Duplicated documents'),
view='documents:duplicated_document_list'
)
link_document_duplicates_list = Link(
args='resolved_object.id', icon_class=icon_duplicated_document_list,
permissions=(permission_document_view,), text=_('Duplicates'),
view='documents:document_duplicates_list',
)
link_duplicated_document_scan = Link(
icon_class=icon_duplicated_document_scan,
permissions=(permission_document_tools,),
text=_('Duplicated document scan'),
view='documents:duplicated_document_scan'
)