diff --git a/HISTORY.rst b/HISTORY.rst index 7d5d0778ef..e1d779a966 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -192,6 +192,8 @@ * Add index create and edit events. * Allow overloading the action_add and action_remove methods from the AddRemoveView. +* Add view to link document type and indexes from the document + type side. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 51e50cd2ed..717555d780 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -224,6 +224,8 @@ Other changes * Add index create and edit events. * Allow overloading the action_add and action_remove methods from the AddRemoveView. +* Add view to link document type and indexes from the document + type side. Removals -------- diff --git a/mayan/apps/document_indexing/apps.py b/mayan/apps/document_indexing/apps.py index 7cfc912c3d..779c4043cd 100644 --- a/mayan/apps/document_indexing/apps.py +++ b/mayan/apps/document_indexing/apps.py @@ -33,7 +33,8 @@ from .html_widgets import ( get_instance_link, index_instance_item_link, node_level ) from .links import ( - link_document_index_instance_list, link_index_instance_menu, link_index_template_setup, + link_document_index_instance_list, link_document_type_index_templates, + link_index_instance_menu, link_index_template_setup, link_index_template_create, link_index_template_document_types, link_index_template_delete, link_index_template_edit, link_index_template_list, link_index_template_node_tree_view, link_index_instances_rebuild, @@ -192,6 +193,10 @@ class DocumentIndexingApp(MayanAppConfig): menu_facet.bind_links( links=(link_document_index_instance_list,), sources=(Document,) ) + menu_list_facet.bind_links( + links=(link_document_type_index_templates,), + sources=(DocumentType,) + ) menu_list_facet.bind_links( links=( link_acl_list, link_events_for_object, diff --git a/mayan/apps/document_indexing/icons.py b/mayan/apps/document_indexing/icons.py index af432bfa5f..304e854881 100644 --- a/mayan/apps/document_indexing/icons.py +++ b/mayan/apps/document_indexing/icons.py @@ -7,6 +7,7 @@ icon_document_index_instance_list = Icon( driver_name='fontawesome', symbol='list-ul' ) icon_index = Icon(driver_name='fontawesome', symbol='list-ul') +icon_document_type_index_templates = icon_index icon_index_level_up = Icon( driver_name='fontawesomecss', css_classes='fa-level-up-alt fa-rotate-90' ) diff --git a/mayan/apps/document_indexing/links.py b/mayan/apps/document_indexing/links.py index 8427e2c29c..fc1f832023 100644 --- a/mayan/apps/document_indexing/links.py +++ b/mayan/apps/document_indexing/links.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _ +from mayan.apps.documents.permissions import permission_document_type_edit from mayan.apps.navigation.classes import Link from mayan.apps.navigation.utils import get_cascade_condition @@ -23,6 +24,13 @@ link_document_index_instance_list = Link( text=_('Indexes'), view='indexing:document_index_list', ) +link_document_type_index_templates = Link( + args='resolved_object.pk', + icon_class_path='mayan.apps.document_indexing.icons.icon_document_type_index_templates', + permissions=(permission_document_type_edit,), text=_('Index templates'), + view='indexing:document_type_index_templates', +) + link_index_instance_menu = Link( condition=get_cascade_condition( app_label='document_indexing', model_name='Index', diff --git a/mayan/apps/document_indexing/models.py b/mayan/apps/document_indexing/models.py index addcf7ff7e..7d8ae9f8a0 100644 --- a/mayan/apps/document_indexing/models.py +++ b/mayan/apps/document_indexing/models.py @@ -12,6 +12,7 @@ from mptt.fields import TreeForeignKey from mptt.models import MPTTModel from mayan.apps.acls.models import AccessControlList +from mayan.apps.documents.events import event_document_type_edited from mayan.apps.documents.models import Document, DocumentType from mayan.apps.documents.permissions import permission_document_view from mayan.apps.lock_manager.exceptions import LockError @@ -48,7 +49,7 @@ class Index(models.Model): verbose_name=_('Enabled') ) document_types = models.ManyToManyField( - to=DocumentType, verbose_name=_('Document types') + related_name='indexes', to=DocumentType, verbose_name=_('Document types') ) objects = IndexManager() @@ -66,14 +67,22 @@ class Index(models.Model): event_index_template_edited.commit( actor=_user, target=self ) - self.document_types.add(*queryset) + for obj in queryset: + self.document_types.add(obj) + event_document_type_edited.commit( + actor=_user, action_object=self, target=obj + ) def document_types_remove(self, queryset, _user=None): with transaction.atomic(): event_index_template_edited.commit( actor=_user, target=self ) - self.document_types.remove(*queryset) + for obj in queryset: + self.document_types.remove(*queryset) + event_document_type_edited.commit( + actor=_user, action_object=self, target=obj + ) def get_absolute_url(self): try: diff --git a/mayan/apps/document_indexing/urls.py b/mayan/apps/document_indexing/urls.py index 5e9eb43e34..380e1d7fdc 100644 --- a/mayan/apps/document_indexing/urls.py +++ b/mayan/apps/document_indexing/urls.py @@ -8,14 +8,19 @@ from .api_views import ( APIIndexTemplateView, APIIndexView ) from .views import ( - DocumentIndexNodeListView, IndexInstanceNodeView, IndexListView, - IndexesRebuildView, SetupIndexDocumentTypesView, SetupIndexCreateView, - SetupIndexDeleteView, SetupIndexEditView, SetupIndexListView, - SetupIndexTreeTemplateListView, TemplateNodeCreateView, + DocumentIndexNodeListView, DocumentTypeIndexesView, IndexInstanceNodeView, + IndexListView, IndexesRebuildView, SetupIndexDocumentTypesView, + SetupIndexCreateView, SetupIndexDeleteView, SetupIndexEditView, + SetupIndexListView, SetupIndexTreeTemplateListView, TemplateNodeCreateView, TemplateNodeDeleteView, TemplateNodeEditView ) urlpatterns = [ + url( + regex=r'^setup/document_types/(?P\d+)/index_templates/$', + view=DocumentTypeIndexesView.as_view(), + name='document_type_index_templates' + ), url( regex=r'^setup/index/list/$', view=SetupIndexListView.as_view(), name='index_setup_list' diff --git a/mayan/apps/document_indexing/views.py b/mayan/apps/document_indexing/views.py index 847f0054c5..6f8b04d9c0 100644 --- a/mayan/apps/document_indexing/views.py +++ b/mayan/apps/document_indexing/views.py @@ -12,12 +12,14 @@ from mayan.apps.common.generics import ( AddRemoveView, FormView, SingleObjectCreateView, SingleObjectDeleteView, SingleObjectEditView, SingleObjectListView ) +from mayan.apps.documents.events import event_document_type_edited from mayan.apps.documents.models import Document, DocumentType from mayan.apps.documents.permissions import ( permission_document_type_edit, permission_document_view ) from mayan.apps.documents.views import DocumentListView +from .events import event_index_template_edited from .forms import IndexTemplateFilteredForm, IndexTemplateNodeForm from .html_widgets import node_tree from .icons import icon_index @@ -35,6 +37,51 @@ from .permissions import ( from .tasks import task_rebuild_index +class DocumentTypeIndexesView(AddRemoveView): + main_object_permission = permission_document_indexing_edit + main_object_model = DocumentType + main_object_pk_url_kwarg = 'pk' + secondary_object_model = Index + secondary_object_permission = permission_document_type_edit + list_available_title = _('Available indexes') + list_added_title = _('Indexes linked') + related_field = 'indexes' + + def action_add(self, queryset, _user): + event_document_type_edited.commit( + actor=_user, target=self.main_object + ) + for obj in queryset: + self.main_object.indexes.add(obj) + event_index_template_edited.commit( + actor=_user, action_object=self.main_object, target=obj + ) + + def action_remove(self, queryset, _user): + event_document_type_edited.commit( + actor=_user, target=self.main_object + ) + for obj in queryset: + self.main_object.indexes.remove(obj) + event_index_template_edited.commit( + actor=_user, action_object=self.main_object, target=obj + ) + + def get_actions_extra_kwargs(self): + return {'_user': self.request.user} + + def get_extra_context(self): + return { + 'object': self.main_object, + 'subtitle': _( + 'Documents of this type will appear in the indexes linked ' + 'when these are updated. Events of the documents of this type ' + 'will trigger updates in the linked indexes.' + ), + 'title': _('Indexes linked to document type: %s') % self.main_object, + } + + # Setup views class SetupIndexCreateView(SingleObjectCreateView): extra_context = {'title': _('Create index')} @@ -104,16 +151,14 @@ class SetupIndexListView(SingleObjectListView): class SetupIndexDocumentTypesView(AddRemoveView): - action_add_method = 'document_types_add' - action_remove_method = 'document_types_remove' + main_object_method_add = 'document_types_add' + main_object_method_remove = 'document_types_remove' main_object_permission = permission_document_indexing_edit main_object_model = Index main_object_pk_url_kwarg = 'pk' secondary_object_model = DocumentType secondary_object_permission = permission_document_type_edit list_available_title = _('Available document types') - # Translators: "User groups" here refer to the group list of a specific - # user. list_added_title = _('Document types linked') related_field = 'document_types'