diff --git a/mayan/apps/document_indexing/admin.py b/mayan/apps/document_indexing/admin.py index 545502b2e6..4a1c4bf42f 100644 --- a/mayan/apps/document_indexing/admin.py +++ b/mayan/apps/document_indexing/admin.py @@ -1,21 +1,29 @@ from __future__ import unicode_literals from django.contrib import admin - -from mptt.admin import MPTTModelAdmin +from django.utils.translation import ugettext_lazy as _ from .models import Index, IndexInstanceNode, IndexTemplateNode -class IndexTemplateNodeAdmin(MPTTModelAdmin): +class IndexTemplateNodeInline(admin.StackedInline): + extra = 0 list_display = ('expression', 'enabled', 'link_documents') + model = IndexTemplateNode -class IndexInstanceNodeAdmin(MPTTModelAdmin): - model = IndexInstanceNode - list_display = ('value',) +class IndexAdmin(admin.ModelAdmin): + filter_horizontal = ('document_types',) + inlines = [IndexTemplateNodeInline] + list_display = ('name', 'title', 'enabled', 'get_document_types') + + def get_document_types(self, instance): + return ', '.join(['"{0}"'.format(document_type) for document_type in instance.document_types.all()]) or _('None') + + get_document_types.short_description = _('Document types') + + +admin.site.register(Index, IndexAdmin) + -admin.site.register(Index) -admin.site.register(IndexTemplateNode, IndexTemplateNodeAdmin) -admin.site.register(IndexInstanceNode, IndexInstanceNodeAdmin) diff --git a/mayan/apps/document_indexing/models.py b/mayan/apps/document_indexing/models.py index 1a0da6fade..ce7fb199fe 100644 --- a/mayan/apps/document_indexing/models.py +++ b/mayan/apps/document_indexing/models.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext, ugettext_lazy as _ from mptt.fields import TreeForeignKey from mptt.models import MPTTModel @@ -68,7 +68,10 @@ class IndexTemplateNode(MPTTModel): link_documents = models.BooleanField(default=False, verbose_name=_('Link documents'), help_text=_('Check this option to have this node act as a container for documents and not as a parent for further nodes.')) def __unicode__(self): - return self.expression + if self.is_root_node(): + return ugettext('<%s Root>') % self.index + else: + return self.expression class Meta: verbose_name = _('Index node template')