Merge and reduce tag widgets
This commit is contained in:
@@ -23,7 +23,7 @@ from .permissions import (
|
|||||||
PERMISSION_TAG_ATTACH, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT,
|
PERMISSION_TAG_ATTACH, PERMISSION_TAG_DELETE, PERMISSION_TAG_EDIT,
|
||||||
PERMISSION_TAG_REMOVE, PERMISSION_TAG_VIEW
|
PERMISSION_TAG_REMOVE, PERMISSION_TAG_VIEW
|
||||||
)
|
)
|
||||||
from .widgets import get_tags_inline_widget_simple, single_tag_widget
|
from .widgets import widget_inline_tags, widget_single_tag
|
||||||
|
|
||||||
|
|
||||||
class TagsApp(MayanAppConfig):
|
class TagsApp(MayanAppConfig):
|
||||||
@@ -35,9 +35,9 @@ class TagsApp(MayanAppConfig):
|
|||||||
|
|
||||||
APIEndPoint('tags')
|
APIEndPoint('tags')
|
||||||
|
|
||||||
SourceColumn(source=Document, label=_('Tags'), attribute=encapsulate(lambda document: get_tags_inline_widget_simple(document)))
|
SourceColumn(source=Document, label=_('Tags'), attribute=encapsulate(lambda document: widget_inline_tags(document)))
|
||||||
|
|
||||||
SourceColumn(source=Tag, label=_('Preview'), attribute=encapsulate(lambda tag: single_tag_widget(tag)))
|
SourceColumn(source=Tag, label=_('Preview'), attribute=encapsulate(lambda tag: widget_single_tag(tag)))
|
||||||
SourceColumn(source=Tag, label=_('Tagged items'), attribute=encapsulate(lambda tag: tag.documents.count()))
|
SourceColumn(source=Tag, label=_('Tagged items'), attribute=encapsulate(lambda tag: tag.documents.count()))
|
||||||
|
|
||||||
class_permissions(Document, [
|
class_permissions(Document, [
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from django.utils.html import escape
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
|
||||||
def get_tags_inline_widget_simple(document):
|
def widget_inline_tags(document):
|
||||||
"""
|
"""
|
||||||
A tag widget that displays the tags for the given document
|
A tag widget that displays the tags for the given document
|
||||||
"""
|
"""
|
||||||
@@ -13,16 +13,14 @@ def get_tags_inline_widget_simple(document):
|
|||||||
tag_count = document.tags.count()
|
tag_count = document.tags.count()
|
||||||
if tag_count:
|
if tag_count:
|
||||||
for tag in document.tags.all():
|
for tag in document.tags.all():
|
||||||
tags_template.append(get_single_tag_template(tag))
|
tags_template.append(widget_single_tag(tag))
|
||||||
|
|
||||||
return mark_safe(''.join(tags_template))
|
return mark_safe(''.join(tags_template))
|
||||||
|
|
||||||
|
|
||||||
def single_tag_widget(tag):
|
def widget_single_tag(tag):
|
||||||
tags_template = []
|
return mark_safe(
|
||||||
tags_template.append(get_single_tag_template(tag))
|
'''
|
||||||
return mark_safe(''.join(tags_template))
|
<span class="label label-tag" style="background: {}">{}</span>
|
||||||
|
'''.format(tag.get_color_code(), escape(tag.label).replace(' ', ' '))
|
||||||
|
)
|
||||||
def get_single_tag_template(tag):
|
|
||||||
return '<span class="label label-tag" style="background: %s">%s</span>' % (tag.get_color_code(), escape(tag.label).replace(' ', ' '))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user