Add document type to indexes link view
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -192,6 +192,8 @@
|
|||||||
* Add index create and edit events.
|
* Add index create and edit events.
|
||||||
* Allow overloading the action_add and action_remove methods
|
* Allow overloading the action_add and action_remove methods
|
||||||
from the AddRemoveView.
|
from the AddRemoveView.
|
||||||
|
* Add view to link document type and indexes from the document
|
||||||
|
type side.
|
||||||
|
|
||||||
3.1.11 (2019-04-XX)
|
3.1.11 (2019-04-XX)
|
||||||
===================
|
===================
|
||||||
|
|||||||
@@ -224,6 +224,8 @@ Other changes
|
|||||||
* Add index create and edit events.
|
* Add index create and edit events.
|
||||||
* Allow overloading the action_add and action_remove methods
|
* Allow overloading the action_add and action_remove methods
|
||||||
from the AddRemoveView.
|
from the AddRemoveView.
|
||||||
|
* Add view to link document type and indexes from the document
|
||||||
|
type side.
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
--------
|
--------
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ from .html_widgets import (
|
|||||||
get_instance_link, index_instance_item_link, node_level
|
get_instance_link, index_instance_item_link, node_level
|
||||||
)
|
)
|
||||||
from .links import (
|
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_create, link_index_template_document_types,
|
||||||
link_index_template_delete, link_index_template_edit, link_index_template_list,
|
link_index_template_delete, link_index_template_edit, link_index_template_list,
|
||||||
link_index_template_node_tree_view, link_index_instances_rebuild,
|
link_index_template_node_tree_view, link_index_instances_rebuild,
|
||||||
@@ -192,6 +193,10 @@ class DocumentIndexingApp(MayanAppConfig):
|
|||||||
menu_facet.bind_links(
|
menu_facet.bind_links(
|
||||||
links=(link_document_index_instance_list,), sources=(Document,)
|
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(
|
menu_list_facet.bind_links(
|
||||||
links=(
|
links=(
|
||||||
link_acl_list, link_events_for_object,
|
link_acl_list, link_events_for_object,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ icon_document_index_instance_list = Icon(
|
|||||||
driver_name='fontawesome', symbol='list-ul'
|
driver_name='fontawesome', symbol='list-ul'
|
||||||
)
|
)
|
||||||
icon_index = 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(
|
icon_index_level_up = Icon(
|
||||||
driver_name='fontawesomecss', css_classes='fa-level-up-alt fa-rotate-90'
|
driver_name='fontawesomecss', css_classes='fa-level-up-alt fa-rotate-90'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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.classes import Link
|
||||||
from mayan.apps.navigation.utils import get_cascade_condition
|
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',
|
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(
|
link_index_instance_menu = Link(
|
||||||
condition=get_cascade_condition(
|
condition=get_cascade_condition(
|
||||||
app_label='document_indexing', model_name='Index',
|
app_label='document_indexing', model_name='Index',
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from mptt.fields import TreeForeignKey
|
|||||||
from mptt.models import MPTTModel
|
from mptt.models import MPTTModel
|
||||||
|
|
||||||
from mayan.apps.acls.models import AccessControlList
|
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.models import Document, DocumentType
|
||||||
from mayan.apps.documents.permissions import permission_document_view
|
from mayan.apps.documents.permissions import permission_document_view
|
||||||
from mayan.apps.lock_manager.exceptions import LockError
|
from mayan.apps.lock_manager.exceptions import LockError
|
||||||
@@ -48,7 +49,7 @@ class Index(models.Model):
|
|||||||
verbose_name=_('Enabled')
|
verbose_name=_('Enabled')
|
||||||
)
|
)
|
||||||
document_types = models.ManyToManyField(
|
document_types = models.ManyToManyField(
|
||||||
to=DocumentType, verbose_name=_('Document types')
|
related_name='indexes', to=DocumentType, verbose_name=_('Document types')
|
||||||
)
|
)
|
||||||
|
|
||||||
objects = IndexManager()
|
objects = IndexManager()
|
||||||
@@ -66,14 +67,22 @@ class Index(models.Model):
|
|||||||
event_index_template_edited.commit(
|
event_index_template_edited.commit(
|
||||||
actor=_user, target=self
|
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):
|
def document_types_remove(self, queryset, _user=None):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
event_index_template_edited.commit(
|
event_index_template_edited.commit(
|
||||||
actor=_user, target=self
|
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):
|
def get_absolute_url(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -8,14 +8,19 @@ from .api_views import (
|
|||||||
APIIndexTemplateView, APIIndexView
|
APIIndexTemplateView, APIIndexView
|
||||||
)
|
)
|
||||||
from .views import (
|
from .views import (
|
||||||
DocumentIndexNodeListView, IndexInstanceNodeView, IndexListView,
|
DocumentIndexNodeListView, DocumentTypeIndexesView, IndexInstanceNodeView,
|
||||||
IndexesRebuildView, SetupIndexDocumentTypesView, SetupIndexCreateView,
|
IndexListView, IndexesRebuildView, SetupIndexDocumentTypesView,
|
||||||
SetupIndexDeleteView, SetupIndexEditView, SetupIndexListView,
|
SetupIndexCreateView, SetupIndexDeleteView, SetupIndexEditView,
|
||||||
SetupIndexTreeTemplateListView, TemplateNodeCreateView,
|
SetupIndexListView, SetupIndexTreeTemplateListView, TemplateNodeCreateView,
|
||||||
TemplateNodeDeleteView, TemplateNodeEditView
|
TemplateNodeDeleteView, TemplateNodeEditView
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
url(
|
||||||
|
regex=r'^setup/document_types/(?P<pk>\d+)/index_templates/$',
|
||||||
|
view=DocumentTypeIndexesView.as_view(),
|
||||||
|
name='document_type_index_templates'
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
regex=r'^setup/index/list/$', view=SetupIndexListView.as_view(),
|
regex=r'^setup/index/list/$', view=SetupIndexListView.as_view(),
|
||||||
name='index_setup_list'
|
name='index_setup_list'
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ from mayan.apps.common.generics import (
|
|||||||
AddRemoveView, FormView, SingleObjectCreateView, SingleObjectDeleteView,
|
AddRemoveView, FormView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||||
SingleObjectEditView, SingleObjectListView
|
SingleObjectEditView, SingleObjectListView
|
||||||
)
|
)
|
||||||
|
from mayan.apps.documents.events import event_document_type_edited
|
||||||
from mayan.apps.documents.models import Document, DocumentType
|
from mayan.apps.documents.models import Document, DocumentType
|
||||||
from mayan.apps.documents.permissions import (
|
from mayan.apps.documents.permissions import (
|
||||||
permission_document_type_edit, permission_document_view
|
permission_document_type_edit, permission_document_view
|
||||||
)
|
)
|
||||||
from mayan.apps.documents.views import DocumentListView
|
from mayan.apps.documents.views import DocumentListView
|
||||||
|
|
||||||
|
from .events import event_index_template_edited
|
||||||
from .forms import IndexTemplateFilteredForm, IndexTemplateNodeForm
|
from .forms import IndexTemplateFilteredForm, IndexTemplateNodeForm
|
||||||
from .html_widgets import node_tree
|
from .html_widgets import node_tree
|
||||||
from .icons import icon_index
|
from .icons import icon_index
|
||||||
@@ -35,6 +37,51 @@ from .permissions import (
|
|||||||
from .tasks import task_rebuild_index
|
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
|
# Setup views
|
||||||
class SetupIndexCreateView(SingleObjectCreateView):
|
class SetupIndexCreateView(SingleObjectCreateView):
|
||||||
extra_context = {'title': _('Create index')}
|
extra_context = {'title': _('Create index')}
|
||||||
@@ -104,16 +151,14 @@ class SetupIndexListView(SingleObjectListView):
|
|||||||
|
|
||||||
|
|
||||||
class SetupIndexDocumentTypesView(AddRemoveView):
|
class SetupIndexDocumentTypesView(AddRemoveView):
|
||||||
action_add_method = 'document_types_add'
|
main_object_method_add = 'document_types_add'
|
||||||
action_remove_method = 'document_types_remove'
|
main_object_method_remove = 'document_types_remove'
|
||||||
main_object_permission = permission_document_indexing_edit
|
main_object_permission = permission_document_indexing_edit
|
||||||
main_object_model = Index
|
main_object_model = Index
|
||||||
main_object_pk_url_kwarg = 'pk'
|
main_object_pk_url_kwarg = 'pk'
|
||||||
secondary_object_model = DocumentType
|
secondary_object_model = DocumentType
|
||||||
secondary_object_permission = permission_document_type_edit
|
secondary_object_permission = permission_document_type_edit
|
||||||
list_available_title = _('Available document types')
|
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')
|
list_added_title = _('Document types linked')
|
||||||
related_field = 'document_types'
|
related_field = 'document_types'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user