diff --git a/HISTORY.rst b/HISTORY.rst index 1bd67c3de5..bf556b56a2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 949ddd3d9d..c023067ab2 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -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 -------- diff --git a/mayan/apps/tags/apps.py b/mayan/apps/tags/apps.py index 3d4c95259a..d31edf12be 100644 --- a/mayan/apps/tags/apps.py +++ b/mayan/apps/tags/apps.py @@ -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): diff --git a/mayan/apps/tags/html_widgets.py b/mayan/apps/tags/html_widgets.py new file mode 100644 index 0000000000..142fa357e8 --- /dev/null +++ b/mayan/apps/tags/html_widgets.py @@ -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} + ) diff --git a/mayan/apps/tags/models.py b/mayan/apps/tags/models.py index dc04737070..62877f2ef3 100644 --- a/mayan/apps/tags/models.py +++ b/mayan/apps/tags/models.py @@ -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 diff --git a/mayan/apps/tags/templates/tags/document_tags_widget.html b/mayan/apps/tags/templates/tags/document_tags_widget.html new file mode 100644 index 0000000000..4d0e6fe825 --- /dev/null +++ b/mayan/apps/tags/templates/tags/document_tags_widget.html @@ -0,0 +1,5 @@ +
+ {% for tag in tags %} + {% include 'tags/tag_widget.html' with tag=tag %} + {% endfor %} +
diff --git a/mayan/apps/tags/widgets.py b/mayan/apps/tags/widgets.py index d008fe888e..c3586142ab 100644 --- a/mayan/apps/tags/widgets.py +++ b/mayan/apps/tags/widgets.py @@ -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 = ['
'] - - 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('
') - - return mark_safe(''.join(result)) - - -def widget_single_tag(tag): - return render_to_string('tags/tag_widget.html', {'tag': tag})