From 19c361937f775eaf499aaec765ea4deb0e356cb4 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 14 May 2011 03:50:06 -0400 Subject: [PATCH] Renamed DocumentMetadataindex model to DocumentIndex and moved it to it's own app --- apps/document_indexing/__init__.py | 0 apps/document_indexing/admin.py | 23 +++++++++++++++++++++++ apps/document_indexing/conf/__init__.py | 0 apps/document_indexing/conf/settings.py | 22 ++++++++++++++++++++++ apps/document_indexing/models.py | 20 ++++++++++++++++++++ apps/document_indexing/tests.py | 23 +++++++++++++++++++++++ apps/document_indexing/views.py | 1 + apps/documents/admin.py | 11 ++--------- apps/documents/models.py | 25 +++---------------------- apps/filesystem_serving/models.py | 5 +++-- settings.py | 6 +++--- 11 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 apps/document_indexing/__init__.py create mode 100644 apps/document_indexing/admin.py create mode 100644 apps/document_indexing/conf/__init__.py create mode 100644 apps/document_indexing/conf/settings.py create mode 100644 apps/document_indexing/models.py create mode 100644 apps/document_indexing/tests.py create mode 100644 apps/document_indexing/views.py diff --git a/apps/document_indexing/__init__.py b/apps/document_indexing/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/document_indexing/admin.py b/apps/document_indexing/admin.py new file mode 100644 index 0000000000..13cdcdaef6 --- /dev/null +++ b/apps/document_indexing/admin.py @@ -0,0 +1,23 @@ +from django.contrib import admin + +from document_indexing.models import DocumentIndex + +#from filesystem_serving.admin import DocumentMetadataIndexInline + + +#class MetadataIndexInline(admin.StackedInline): +# model = MetadataIndex +# extra = 1 +# classes = ('collapse-open',) +# allow_add = True + + +class DocumentIndexAdmin(admin.ModelAdmin): + pass + #inlines = [ + # DocumentMetadataIndexInline, + # + + + +admin.site.register(DocumentIndex, DocumentIndexAdmin) diff --git a/apps/document_indexing/conf/__init__.py b/apps/document_indexing/conf/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/document_indexing/conf/settings.py b/apps/document_indexing/conf/settings.py new file mode 100644 index 0000000000..1fc19e2e51 --- /dev/null +++ b/apps/document_indexing/conf/settings.py @@ -0,0 +1,22 @@ +"""Configuration options for the document_indexing app""" + +import hashlib +import uuid + +from django.utils.translation import ugettext_lazy as _ + +from common.utils import proper_name +from smart_settings.api import register_settings + +available_indexing_functions = { + 'proper_name': proper_name +} + +register_settings( + namespace=u'document_indexing', + module=u'document_indexing.conf.settings', + settings=[ + # Definition + {'name': u'AVAILABLE_INDEXING_FUNCTIONS', 'global_name': u'DOCUMENT_INDEXING_AVAILABLE_INDEXING_FUNCTIONS', 'default': available_indexing_functions}, + ] +) diff --git a/apps/document_indexing/models.py b/apps/document_indexing/models.py new file mode 100644 index 0000000000..8865f49a5c --- /dev/null +++ b/apps/document_indexing/models.py @@ -0,0 +1,20 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from document_indexing.conf.settings import AVAILABLE_INDEXING_FUNCTIONS + +available_indexing_functions_string = (_(u' Available functions: %s') % u','.join([u'%s()' % name for name, function in AVAILABLE_INDEXING_FUNCTIONS.items()])) if AVAILABLE_INDEXING_FUNCTIONS else u'' + + +class DocumentIndex(models.Model): + expression = models.CharField(max_length=128, + verbose_name=_(u'indexing expression'), + help_text=_(u'Enter a python string expression to be evaluated. The slash caracter "/" acts as a directory delimiter.%s') % available_indexing_functions_string) + enabled = models.BooleanField(default=True, verbose_name=_(u'enabled')) + + def __unicode__(self): + return unicode(self.expression) + + class Meta: + verbose_name = _(u'metadata index') + verbose_name_plural = _(u'metadata indexes') diff --git a/apps/document_indexing/tests.py b/apps/document_indexing/tests.py new file mode 100644 index 0000000000..2247054b35 --- /dev/null +++ b/apps/document_indexing/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/apps/document_indexing/views.py b/apps/document_indexing/views.py new file mode 100644 index 0000000000..60f00ef0ef --- /dev/null +++ b/apps/document_indexing/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/apps/documents/admin.py b/apps/documents/admin.py index 94ff09a3c1..78865e6879 100644 --- a/apps/documents/admin.py +++ b/apps/documents/admin.py @@ -3,19 +3,12 @@ from django.contrib import admin from metadata.admin import DocumentMetadataInline from documents.models import DocumentType, Document, \ - DocumentTypeFilename, MetadataIndex, DocumentPage, \ + DocumentTypeFilename, DocumentPage, \ DocumentPageTransformation, RecentDocument from filesystem_serving.admin import DocumentMetadataIndexInline -class MetadataIndexInline(admin.StackedInline): - model = MetadataIndex - extra = 1 - classes = ('collapse-open',) - allow_add = True - - class DocumentTypeFilenameInline(admin.StackedInline): model = DocumentTypeFilename extra = 1 @@ -25,7 +18,7 @@ class DocumentTypeFilenameInline(admin.StackedInline): class DocumentTypeAdmin(admin.ModelAdmin): inlines = [ - DocumentTypeFilenameInline, MetadataIndexInline + DocumentTypeFilenameInline ] diff --git a/apps/documents/models.py b/apps/documents/models.py index 6491736632..406157d9f0 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -17,7 +17,6 @@ from converter.api import get_page_count from converter import TRANFORMATION_CHOICES from metadata.classes import MetadataObject -from documents.conf.settings import AVAILABLE_INDEXING_FUNCTIONS from documents.conf.settings import CHECKSUM_FUNCTION from documents.conf.settings import UUID_FUNCTION from documents.conf.settings import STORAGE_BACKEND @@ -25,6 +24,9 @@ from documents.conf.settings import AVAILABLE_TRANSFORMATIONS from documents.conf.settings import DEFAULT_TRANSFORMATIONS from documents.conf.settings import RECENT_COUNT +available_transformations = ([(name, data['label']) for name, data in AVAILABLE_TRANSFORMATIONS.items()]) + + def get_filename_from_uuid(instance, filename): filename, extension = os.path.splitext(filename) instance.file_filename = filename @@ -201,22 +203,6 @@ class Document(models.Model): page_transformation.save() -available_indexing_functions_string = (_(u' Available functions: %s') % u','.join([u'%s()' % name for name, function in AVAILABLE_INDEXING_FUNCTIONS.items()])) if AVAILABLE_INDEXING_FUNCTIONS else u'' - -class MetadataIndex(models.Model): - document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type')) - expression = models.CharField(max_length=128, - verbose_name=_(u'indexing expression'), - help_text=_(u'Enter a python string expression to be evaluated. The slash caracter "/" acts as a directory delimiter.%s') % available_indexing_functions_string) - enabled = models.BooleanField(default=True, verbose_name=_(u'enabled')) - - def __unicode__(self): - return unicode(self.expression) - - class Meta: - verbose_name = _(u'metadata index') - verbose_name_plural = _(u'metadata indexes') - class DocumentTypeFilename(models.Model): """ @@ -272,11 +258,6 @@ class DocumentPage(models.Model): return ' '.join(transformation_list), warnings - - -available_transformations = ([(name, data['label']) for name, data in AVAILABLE_TRANSFORMATIONS.items()]) - - class DocumentPageTransformation(models.Model): document_page = models.ForeignKey(DocumentPage, verbose_name=_(u'document page')) order = models.PositiveIntegerField(default=0, blank=True, null=True, verbose_name=_(u'order'), db_index=True) diff --git a/apps/filesystem_serving/models.py b/apps/filesystem_serving/models.py index 3e3294d5e3..f513e8c299 100644 --- a/apps/filesystem_serving/models.py +++ b/apps/filesystem_serving/models.py @@ -1,12 +1,13 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -from documents.models import Document, MetadataIndex +from documents.models import Document +from document_indexing.models import DocumentIndex class DocumentMetadataIndex(models.Model): document = models.ForeignKey(Document, verbose_name=_(u'document')) - metadata_index = models.ForeignKey(MetadataIndex, verbose_name=_(u'metadata index')) + metadata_index = models.ForeignKey(DocumentIndex, verbose_name=_(u'document index')) filename = models.CharField(max_length=255, verbose_name=_(u'filename')) suffix = models.PositiveIntegerField(default=0, verbose_name=_(u'suffix')) diff --git a/settings.py b/settings.py index 1296bde3f3..60a37518b2 100644 --- a/settings.py +++ b/settings.py @@ -147,6 +147,7 @@ INSTALLED_APPS = ( 'user_management', 'documents', 'grouping', + 'document_indexing', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -181,10 +182,9 @@ TEMPLATE_CONTEXT_PROCESSORS = ( #---------- Metadata ----------------- # METADATA_AVAILABLE_FUNCTIONS = {} # METADATA_AVAILABLE_MODELS = {} +#---------- Indexing ----------------- +#DOCUMENT_INDEXING_AVAILABLE_INDEXING_FUNCTIONS = {} #---------- Documents ------------------ -# Definition -#DOCUMENTS_INDEXING_AVAILABLE_FUNCTIONS = {} - # Upload #DOCUMENTS_USE_STAGING_DIRECTORY = False #DOCUMENTS_STAGING_DIRECTORY = u'/tmp/mayan/staging'