Refactor document indexing app

Convert half the widget to HTML widgets.

Rename links and views to use the nomeclature _template_
and _instance_ to differenciate between index instances
and index templates.

Update URL parameters to use the "_id" form.

Add more tests.

Add model permission inheritance to the IndexTemplateNode,
and IndexInstanceNode models.

Remove the level and document count display from the
instance node. Display instead the total items.

Use a FilteredSelectionForm subclass to display the list
of index templates to rebuild.

Add missing icons.

Add keyword arguments to links.

Modernize tests to use the document test mixin.

Update the permission requirements for the index template
document type selection screen. The document type view
permission is now required in addition to the index
template edit permission.

Use ExternalObjectMixin to reduce the code in all views.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-02-05 05:40:01 -04:00
parent 4ab2b4fee0
commit bd12d587ee
17 changed files with 947 additions and 680 deletions

View File

@@ -0,0 +1,74 @@
from __future__ import unicode_literals
from django.template.loader import render_to_string
from django.utils.html import escape, mark_safe
from .icons import (
icon_index, icon_index_level_up,
icon_index_instance_node_with_documents
)
class IndexInstanceNodeWidget(object):
def render(self, name, value):
return render_to_string(
template_name='document_indexing/index_instance_node.html',
context={
'index_instance_node': value,
}
)
class IndexTemplateNodeIndentationWidget(object):
def render(self, name, value):
return render_to_string(
template_name='document_indexing/index_template_node_indentation.html',
context={
'index_template_node': value,
'index_template_node_level': range(value.get_level()),
}
)
def get_instance_link(index_instance_node):
"""
Return an HTML anchor to an index node instance
"""
return mark_safe(
s='<a href="{url}">{text}</a>'.format(
url=index_instance_node.get_absolute_url(),
text=escape(index_instance_node.get_full_path())
)
)
def node_tree(node, user):
#TODO: Replace with a file template
result = []
result.append('<div class="list-group">')
for ancestor in node.get_ancestors(include_self=True):
if ancestor.is_root_node():
element = node.index()
icon = icon_index
else:
element = ancestor
if element.index_template_node.link_documents:
icon = icon_index_instance_node_with_documents
else:
icon = icon_index_level_up
result.append(
'<a href="{url}" class="list-group-item {active}"><span class="badge">{count}</span>{icon} {text}</a>'.format(
url=element.get_absolute_url(),
active='active' if element == node or node.get_ancestors(include_self=True).count() == 1 else '',
count=element.get_item_count(user=user),
icon=icon.render(),
text=escape(element)
)
)
result.append('</div>')
return mark_safe(s=''.join(result))