Moved get_metadata_string Document class method to the metadata app

This commit is contained in:
Roberto Rosario
2011-07-02 00:44:12 -04:00
parent f183153b1c
commit 0fa1e0c706
3 changed files with 9 additions and 7 deletions

View File

@@ -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)
},
])

View File

@@ -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:

View File

@@ -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')])