Convert half the widget to HTML widgets. Rename links and views to use the nomeclature _template_ and _instance_ to differenciate between index instances and index templates. Update URL parameters to use the "_id" form. Add more tests. Add model permission inheritance to the IndexTemplateNode, and IndexInstanceNode models. Remove the level and document count display from the instance node. Display instead the total items. Use a FilteredSelectionForm subclass to display the list of index templates to rebuild. Add missing icons. Add keyword arguments to links. Modernize tests to use the document test mixin. Update the permission requirements for the index template document type selection screen. The document type view permission is now required in addition to the index template edit permission. Use ExternalObjectMixin to reduce the code in all views. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
244 lines
8.6 KiB
Python
244 lines
8.6 KiB
Python
from __future__ import absolute_import, unicode_literals
|
|
|
|
from django.apps import apps
|
|
from django.db.models.signals import post_delete, post_save, pre_delete
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from kombu import Exchange, Queue
|
|
|
|
from mayan.apps.acls import ModelPermission
|
|
from mayan.apps.acls.links import link_acl_list
|
|
from mayan.apps.acls.permissions import (
|
|
permission_acl_edit, permission_acl_view
|
|
)
|
|
from mayan.apps.common import (
|
|
MayanAppConfig, menu_facet, menu_list_facet, menu_main, menu_object,
|
|
menu_secondary, menu_setup, menu_tools
|
|
)
|
|
from mayan.apps.common.widgets import TwoStateWidget
|
|
from mayan.apps.documents.signals import (
|
|
post_document_created, post_initial_document_type
|
|
)
|
|
from mayan.apps.navigation import SourceColumn
|
|
from mayan.celery import app
|
|
|
|
from .handlers import (
|
|
handler_create_default_document_index, handler_delete_empty,
|
|
handler_index_document, handler_post_save_index_document,
|
|
handler_remove_document
|
|
)
|
|
from .html_widgets import (
|
|
IndexInstanceNodeWidget, IndexTemplateNodeIndentationWidget,
|
|
get_instance_link
|
|
)
|
|
from .licenses import * # NOQA
|
|
from .links import (
|
|
link_document_index_instance_list, link_index_instances_rebuild,
|
|
link_index_main_menu, link_index_setup, link_index_template_create,
|
|
link_index_template_delete, link_index_template_document_types,
|
|
link_index_template_edit, link_index_template_list,
|
|
link_index_template_view, link_index_template_node_create,
|
|
link_index_template_node_delete, link_index_template_node_edit
|
|
)
|
|
from .permissions import (
|
|
permission_document_indexing_create, permission_document_indexing_delete,
|
|
permission_document_indexing_edit, permission_document_indexing_instance_view,
|
|
permission_document_indexing_rebuild, permission_document_indexing_view
|
|
)
|
|
from .queues import * # NOQA
|
|
|
|
|
|
class DocumentIndexingApp(MayanAppConfig):
|
|
app_namespace = 'indexing'
|
|
app_url = 'indexing'
|
|
has_rest_api = True
|
|
has_tests = True
|
|
name = 'mayan.apps.document_indexing'
|
|
verbose_name = _('Document indexing')
|
|
|
|
def ready(self):
|
|
super(DocumentIndexingApp, self).ready()
|
|
|
|
Document = apps.get_model(
|
|
app_label='documents', model_name='Document'
|
|
)
|
|
|
|
DocumentType = apps.get_model(
|
|
app_label='documents', model_name='DocumentType'
|
|
)
|
|
|
|
DocumentIndexInstanceNode = self.get_model(
|
|
model_name='DocumentIndexInstanceNode'
|
|
)
|
|
|
|
Index = self.get_model(model_name='Index')
|
|
IndexInstance = self.get_model(model_name='IndexInstance')
|
|
IndexInstanceNode = self.get_model(model_name='IndexInstanceNode')
|
|
IndexTemplateNode = self.get_model(model_name='IndexTemplateNode')
|
|
|
|
ModelPermission.register(
|
|
model=Index, permissions=(
|
|
permission_acl_edit, permission_acl_view,
|
|
permission_document_indexing_create,
|
|
permission_document_indexing_delete,
|
|
permission_document_indexing_edit,
|
|
permission_document_indexing_instance_view,
|
|
permission_document_indexing_rebuild,
|
|
permission_document_indexing_view,
|
|
)
|
|
)
|
|
|
|
ModelPermission.register_inheritance(
|
|
model=IndexTemplateNode, related='index'
|
|
)
|
|
|
|
ModelPermission.register_inheritance(
|
|
model=IndexInstanceNode, related='index_template_node__index'
|
|
)
|
|
|
|
SourceColumn(
|
|
attribute='label', is_identifier=True, is_sortable=True, source=Index
|
|
)
|
|
SourceColumn(
|
|
attribute='slug', include_label=True, is_sortable=True, source=Index
|
|
)
|
|
SourceColumn(
|
|
attribute='enabled', include_label=True, is_sortable=True,
|
|
source=Index, widget=TwoStateWidget
|
|
)
|
|
|
|
SourceColumn(
|
|
func=lambda context: context[
|
|
'object'
|
|
].instance_root.get_descendants_count(), include_label=True,
|
|
label=_('Total levels'), source=IndexInstance,
|
|
)
|
|
SourceColumn(
|
|
func=lambda context: context[
|
|
'object'
|
|
].instance_root.get_descendants_document_count(
|
|
user=context['request'].user
|
|
), include_label=True, label=_('Total documents'), source=IndexInstance
|
|
)
|
|
SourceColumn(
|
|
label=_('Level'), is_identifier=True, source=IndexTemplateNode,
|
|
widget=IndexTemplateNodeIndentationWidget
|
|
)
|
|
SourceColumn(
|
|
attribute='enabled', include_label=True, is_sortable=True,
|
|
source=IndexTemplateNode, widget=TwoStateWidget
|
|
)
|
|
SourceColumn(
|
|
attribute='link_documents', include_label=True,
|
|
is_sortable=True, source=IndexTemplateNode, widget=TwoStateWidget
|
|
)
|
|
|
|
SourceColumn(
|
|
is_identifier=True, is_sortable=True, label=_('Level'),
|
|
sort_field='value', source=IndexInstanceNode,
|
|
widget=IndexInstanceNodeWidget
|
|
)
|
|
|
|
SourceColumn(
|
|
func=lambda context: context[
|
|
'object'
|
|
].get_item_count(
|
|
user=context['request'].user
|
|
), include_label=True, label=_('Items'), source=IndexInstanceNode
|
|
)
|
|
|
|
SourceColumn(
|
|
func=lambda context: get_instance_link(
|
|
index_instance_node=context['object'],
|
|
), label=_('Level'), source=DocumentIndexInstanceNode
|
|
)
|
|
SourceColumn(
|
|
func=lambda context: context['object'].get_descendants_count(),
|
|
label=_('Levels'), source=DocumentIndexInstanceNode
|
|
)
|
|
SourceColumn(
|
|
func=lambda context: context[
|
|
'object'
|
|
].get_descendants_document_count(
|
|
user=context['request'].user
|
|
), label=_('Documents'), source=DocumentIndexInstanceNode
|
|
)
|
|
|
|
app.conf.task_queues.append(
|
|
Queue('indexing', Exchange('indexing'), routing_key='indexing'),
|
|
)
|
|
|
|
app.conf.task_routes.update(
|
|
{
|
|
'mayan.apps.document_indexing.tasks.task_delete_empty': {
|
|
'queue': 'indexing'
|
|
},
|
|
'mayan.apps.document_indexing.tasks.task_remove_document': {
|
|
'queue': 'indexing'
|
|
},
|
|
'mayan.apps.document_indexing.tasks.task_index_document': {
|
|
'queue': 'indexing'
|
|
},
|
|
'mayan.apps.document_indexing.tasks.task_rebuild_index': {
|
|
'queue': 'tools'
|
|
},
|
|
}
|
|
)
|
|
|
|
menu_facet.bind_links(
|
|
links=(link_document_index_instance_list,), sources=(Document,)
|
|
)
|
|
menu_list_facet.bind_links(
|
|
links=(
|
|
link_acl_list, link_index_template_document_types,
|
|
link_index_template_view,
|
|
), sources=(Index,)
|
|
)
|
|
menu_object.bind_links(
|
|
links=(
|
|
link_index_template_edit, link_index_template_delete
|
|
), sources=(Index,)
|
|
)
|
|
menu_object.bind_links(
|
|
links=(
|
|
link_index_template_node_create, link_index_template_node_edit,
|
|
link_index_template_node_delete
|
|
), sources=(IndexTemplateNode,)
|
|
)
|
|
menu_main.bind_links(links=(link_index_main_menu,), position=98)
|
|
menu_secondary.bind_links(
|
|
links=(link_index_template_list, link_index_template_create),
|
|
sources=(
|
|
Index, 'indexing:index_template_list',
|
|
'indexing:index_template_create'
|
|
)
|
|
)
|
|
menu_setup.bind_links(links=(link_index_setup,))
|
|
menu_tools.bind_links(links=(link_index_instances_rebuild,))
|
|
|
|
post_delete.connect(
|
|
dispatch_uid='document_indexing_handler_delete_empty',
|
|
receiver=handler_delete_empty,
|
|
sender=Document
|
|
)
|
|
post_document_created.connect(
|
|
dispatch_uid='document_indexing_handler_index_document',
|
|
receiver=handler_index_document,
|
|
sender=Document
|
|
)
|
|
post_initial_document_type.connect(
|
|
dispatch_uid='document_indexing_handler_create_default_document_index',
|
|
receiver=handler_create_default_document_index,
|
|
sender=DocumentType
|
|
)
|
|
post_save.connect(
|
|
dispatch_uid='document_indexing_handler_post_save_index_document',
|
|
receiver=handler_post_save_index_document,
|
|
sender=Document
|
|
)
|
|
pre_delete.connect(
|
|
dispatch_uid='document_indexing_handler_remove_document',
|
|
receiver=handler_remove_document,
|
|
sender=Document
|
|
)
|