Display document tags in the document list view
This commit is contained in:
@@ -6,6 +6,7 @@ from navigation.api import register_links, register_menu, \
|
||||
register_model_list_columns, register_multi_item_links
|
||||
from main.api import register_diagnostic, register_tool
|
||||
from permissions.api import register_permissions
|
||||
from tags.widgets import get_tags_inline_widget_simple
|
||||
|
||||
from documents.models import Document, DocumentPage, DocumentPageTransformation
|
||||
from documents.staging import StagingFile
|
||||
@@ -135,6 +136,9 @@ register_model_list_columns(Document, [
|
||||
'string': _(u'thumbnail')
|
||||
}
|
||||
},
|
||||
{'name':_(u'tags'), 'attribute':
|
||||
lambda x: get_tags_inline_widget_simple(x)
|
||||
},
|
||||
{'name':_(u'metadata'), 'attribute':
|
||||
lambda x: x.get_metadata_string()
|
||||
},
|
||||
|
||||
@@ -9,14 +9,13 @@ from django.forms.formsets import formset_factory
|
||||
from django.template.defaultfilters import capfirst
|
||||
from django.conf import settings
|
||||
|
||||
from documents.staging import StagingFile
|
||||
|
||||
from tags.widgets import get_tags_inline_widget
|
||||
from common.wizard import BoundFormWizard
|
||||
from common.forms import DetailForm
|
||||
|
||||
from documents.staging import StagingFile
|
||||
from documents.models import Document, DocumentType, DocumentTypeMetadataType, \
|
||||
DocumentPage, DocumentPageTransformation
|
||||
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
from documents.conf.settings import AVAILABLE_MODELS
|
||||
|
||||
@@ -366,18 +365,7 @@ class MetaDataImageWidget(forms.widgets.Widget):
|
||||
|
||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||
for document in value['group_data']:
|
||||
tags_template = []
|
||||
tag_block_template = u'<div style="padding: 0px 5px 0px 5px; border: 1px solid black; background: %s;">%s</div>'
|
||||
tag_count = document.tags.count()
|
||||
if tag_count:
|
||||
tags_template.append(u'<div class="tc">')
|
||||
tags_template.append(u'<div>%(tag_string)s: %(tag_count)s</div>' % {
|
||||
'tag_string': _(u'Tags'), 'tag_count': tag_count})
|
||||
|
||||
for tag in document.tags.all():
|
||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||
|
||||
tags_template.append(u'</div>')
|
||||
tags_template = get_tags_inline_widget(document)
|
||||
|
||||
output.append(
|
||||
u'''<div style="display: inline-block; margin: 10px; %(current)s">
|
||||
@@ -406,7 +394,7 @@ class MetaDataImageWidget(forms.widgets.Widget):
|
||||
'group_id': value['group'].pk,
|
||||
'document_name': document,
|
||||
'media_url': settings.MEDIA_URL,
|
||||
'tags_template': u''.join(tags_template) if tags_template else u'',
|
||||
'tags_template': tags_template if tags_template else u'',
|
||||
'string': _(u'group document'),
|
||||
})
|
||||
output.append(u'</div>')
|
||||
|
||||
31
apps/tags/widgets.py
Normal file
31
apps/tags/widgets.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def get_tags_inline_widget(document):
|
||||
tags_template = []
|
||||
tag_block_template = u'<div style="padding: 0px 5px 0px 5px; border: 1px solid black; background: %s;">%s</div>'
|
||||
tag_count = document.tags.count()
|
||||
if tag_count:
|
||||
tags_template.append(u'<div class="tc">')
|
||||
tags_template.append(u'<div>%(tag_string)s: %(tag_count)s</div>' % {
|
||||
'tag_string': _(u'Tags'), 'tag_count': tag_count})
|
||||
|
||||
for tag in document.tags.all():
|
||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||
|
||||
tags_template.append(u'</div>')
|
||||
return u''.join(tags_template)
|
||||
|
||||
|
||||
def get_tags_inline_widget_simple(document):
|
||||
tags_template = []
|
||||
tag_block_template = u'<div style="padding: 0px 5px 0px 5px; border: 1px solid black; background: %s;">%s</div>'
|
||||
tag_count = document.tags.count()
|
||||
if tag_count:
|
||||
tags_template.append(u'<div class="tc">')
|
||||
|
||||
for tag in document.tags.all():
|
||||
tags_template.append(tag_block_template % (tag.tagproperties_set.get().get_color_code(), tag.name))
|
||||
|
||||
tags_template.append(u'</div>')
|
||||
return u''.join(tags_template)
|
||||
Reference in New Issue
Block a user