diff --git a/apps/documents/__init__.py b/apps/documents/__init__.py index 98496ac6fa..eb55905949 100644 --- a/apps/documents/__init__.py +++ b/apps/documents/__init__.py @@ -9,6 +9,7 @@ from main.api import register_diagnostic, register_tool from permissions.api import register_permission, set_namespace_title from tags.widgets import get_tags_inline_widget_simple from history.api import register_history_type +from metadata.api import get_metadata_string from documents.models import Document, DocumentPage, \ DocumentPageTransformation, DocumentType, DocumentTypeFilename @@ -189,7 +190,7 @@ register_model_list_columns(Document, [ lambda x: get_tags_inline_widget_simple(x) }, {'name':_(u'metadata'), 'attribute': - lambda x: x.get_metadata_string() + lambda x: get_metadata_string(x) }, ]) diff --git a/apps/documents/models.py b/apps/documents/models.py index ab50727c21..39306893c0 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -204,12 +204,6 @@ class Document(models.Model): """ return self.file.storage.exists(self.file.path) - def get_metadata_string(self): - """ - Return a formated representation of a document's metadata values - """ - return u', '.join([u'%s - %s' % (metadata.metadata_type, metadata.value) for metadata in self.documentmetadata_set.select_related('metadata_type', 'document').defer('document__document_type', 'document__file', 'document__description', 'document__file_filename', 'document__uuid', 'document__date_added', 'document__date_updated', 'document__file_mimetype', 'document__file_mime_encoding')]) - def apply_default_transformations(self): #Only apply default transformations on new documents if DEFAULT_TRANSFORMATIONS and reduce(lambda x, y: x + y, [page.documentpagetransformation_set.count() for page in self.documentpage_set.all()]) == 0: diff --git a/apps/metadata/api.py b/apps/metadata/api.py index 26f93b6bce..3208ef7e23 100644 --- a/apps/metadata/api.py +++ b/apps/metadata/api.py @@ -95,3 +95,10 @@ def metadata_repr_as_list(metadata_list): pass return output + + +def get_metadata_string(document): + """ + Return a formated representation of a document's metadata values + """ + return u', '.join([u'%s - %s' % (metadata.metadata_type, metadata.value) for metadata in DocumentMetadata.objects.filter(document=document).select_related('metadata_type')])