Convert document tags widget to use HTML templates

Move Tag app HTML widgets to their own module.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-16 00:07:06 -04:00
parent 030ee8efe3
commit 0cdba79738
7 changed files with 40 additions and 33 deletions

View File

@@ -78,6 +78,8 @@
class initialization.
* Remove star import from the ACL and Common apps.
* Add dependencies app
* Convert the document tags widget to use HTML templates.
* Move Tag app HTML widgets to their own module.
3.1.11 (2019-04-XX)
===================

View File

@@ -110,6 +110,8 @@ Other changes
class initialization.
* Remove star import from the ACL and Common apps.
* Add dependencies app
* Convert the document tags widget to use HTML templates.
* Move Tag app HTML widgets to their own module.
Removals
--------

View File

@@ -24,6 +24,7 @@ from .events import (
event_tag_attach, event_tag_created, event_tag_edited, event_tag_remove
)
from .handlers import handler_index_document, handler_tag_pre_delete
from .html_widgets import widget_document_tags
from .links import (
link_multiple_documents_attach_tag, link_multiple_documents_tag_remove,
link_single_document_multiple_tag_remove, link_tag_attach, link_tag_create,
@@ -37,7 +38,6 @@ from .permissions import (
permission_tag_remove, permission_tag_view
)
from .search import tag_search # NOQA
from .widgets import widget_document_tags
class TagsApp(MayanAppConfig):

View File

@@ -0,0 +1,29 @@
from __future__ import absolute_import, unicode_literals
from django.apps import apps
from django.template.loader import render_to_string
from .permissions import permission_tag_view
def widget_document_tags(document, user):
"""
A tag widget that displays the tags for the given document
"""
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
tags = AccessControlList.objects.filter_by_access(
permission_tag_view, user, queryset=document.attached_tags().all()
)
return render_to_string(
template_name='tags/document_tags_widget.html', context={'tags': tags}
)
def widget_single_tag(tag):
return render_to_string(
template_name='tags/tag_widget.html', context={'tag': tag}
)

View File

@@ -14,7 +14,7 @@ from mayan.apps.documents.permissions import permission_document_view
from .events import (
event_tag_attach, event_tag_created, event_tag_edited, event_tag_remove
)
from .widgets import widget_single_tag
from .html_widgets import widget_single_tag
@python_2_unicode_compatible

View File

@@ -0,0 +1,5 @@
<div class="tag-container">
{% for tag in tags %}
{% include 'tags/tag_widget.html' with tag=tag %}
{% endfor %}
</div>

View File

@@ -1,12 +1,7 @@
from __future__ import absolute_import, unicode_literals
from django import forms
from django.apps import apps
from django.template.loader import render_to_string
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from .permissions import permission_tag_view
class TagFormWidget(forms.SelectMultiple):
@@ -23,29 +18,3 @@ class TagFormWidget(forms.SelectMultiple):
result['attrs']['data-color'] = self.choices.queryset.get(pk=value).color
return result
def widget_document_tags(document, user):
"""
A tag widget that displays the tags for the given document
"""
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
result = ['<div class="tag-container">']
tags = AccessControlList.objects.filter_by_access(
permission_tag_view, user, queryset=document.attached_tags().all()
)
for tag in tags:
result.append(widget_single_tag(tag))
result.append('</div>')
return mark_safe(''.join(result))
def widget_single_tag(tag):
return render_to_string('tags/tag_widget.html', {'tag': tag})