Ensure that the automatic index is created after the default document type is created.

This commit is contained in:
Roberto Rosario
2016-05-17 05:02:57 -04:00
parent 0bebef5ba9
commit c97208f609
5 changed files with 36 additions and 20 deletions

View File

@@ -17,7 +17,7 @@ from common import (
from common.classes import Package
from common.signals import post_initial_setup
from common.widgets import two_state_template
from documents.signals import post_document_created
from documents.signals import post_document_created, post_initial_document_type
from mayan.celery import app
from navigation import SourceColumn
from rest_api.classes import APIEndPoint
@@ -56,6 +56,10 @@ class DocumentIndexingApp(MayanAppConfig):
app_label='documents', model_name='Document'
)
DocumentType = apps.get_model(
app_label='documents', model_name='DocumentType'
)
DocumentMetadata = apps.get_model(
app_label='metadata', model_name='DocumentMetadata'
)
@@ -234,9 +238,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
document_created_index_update,
dispatch_uid='document_created_index_update', sender=Document
)
post_initial_setup.connect(
post_initial_document_type.connect(
create_default_document_index,
dispatch_uid='create_default_document_index'
dispatch_uid='create_default_document_index', sender=DocumentType
)
post_save.connect(
document_metadata_index_update,

View File

@@ -3,6 +3,8 @@ from __future__ import unicode_literals
from django.apps import apps
from django.utils.translation import ugettext_lazy as _
from documents.literals import DEFAULT_DOCUMENT_TYPE_LABEL
from .tasks import task_delete_empty_index_nodes, task_index_document
@@ -14,23 +16,21 @@ def create_default_document_index(sender, **kwargs):
app_label='document_indexing', model_name='Index'
)
if not Index.objects.count():
index = Index.objects.create(
label=_('Creation date'), slug='creation_date'
)
for document_type in DocumentType.objects.all():
index.document_types.add(document_type)
root_template_node = index.template_root
node = root_template_node.get_children().create(
expression='{{ document.date_added|date:"Y" }}', index=index,
parent=root_template_node
)
node.get_children().create(
expression='{{ document.date_added|date:"m" }}',
index=index, link_documents=True, parent=node
)
index = Index.objects.create(
label=_('Creation date'), slug='creation_date'
)
for document_type in DocumentType.objects.all():
index.document_types.add(document_type)
root_template_node = index.template_root
node = root_template_node.get_children().create(
expression='{{ document.date_added|date:"Y" }}', index=index,
parent=root_template_node
)
node.get_children().create(
expression='{{ document.date_added|date:"m" }}',
index=index, link_documents=True, parent=node
)
def document_created_index_update(sender, **kwargs):