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:
@@ -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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
--------
|
||||
|
||||
@@ -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):
|
||||
|
||||
29
mayan/apps/tags/html_widgets.py
Normal file
29
mayan/apps/tags/html_widgets.py
Normal 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}
|
||||
)
|
||||
@@ -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
|
||||
|
||||
5
mayan/apps/tags/templates/tags/document_tags_widget.html
Normal file
5
mayan/apps/tags/templates/tags/document_tags_widget.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class="tag-container">
|
||||
{% for tag in tags %}
|
||||
{% include 'tags/tag_widget.html' with tag=tag %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user