Move all widgets code to a single module
This commit is contained in:
@@ -3,7 +3,6 @@ from __future__ import absolute_import
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.template.defaultfilters import slugify
|
||||
|
||||
from documents.models import Document
|
||||
@@ -17,6 +16,8 @@ from .filesystem import (fs_create_index_directory,
|
||||
fs_create_document_link, fs_delete_document_link,
|
||||
fs_delete_index_directory, fs_delete_directory_recusive,
|
||||
assemble_suffixed_filename)
|
||||
from .widgets import get_instance_link
|
||||
from .exceptions import MaxSuffixCountReached
|
||||
|
||||
if SLUGIFY_PATHS == False:
|
||||
# Do not slugify path or filenames and extensions
|
||||
@@ -25,10 +26,6 @@ else:
|
||||
SLUGIFY_FUNCTION = slugify
|
||||
|
||||
|
||||
class MaxSuffixCountReached(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# External functions
|
||||
def update_indexes(document):
|
||||
"""
|
||||
@@ -63,55 +60,6 @@ def delete_indexes(document):
|
||||
return warnings
|
||||
|
||||
|
||||
def get_instance_link(index_instance_node, text=None, simple=False):
|
||||
"""
|
||||
Return an HTML anchor to an index instance
|
||||
"""
|
||||
|
||||
if simple:
|
||||
# Just display the instance's value or overrided text, no
|
||||
# HTML anchor
|
||||
template = u'%(value)s'
|
||||
else:
|
||||
template = u'<a href="%(url)s">%(value)s</a>'
|
||||
|
||||
return template % {
|
||||
'url': index_instance_node.get_absolute_url(),
|
||||
'value': text if text else (index_instance_node if index_instance_node.parent else index_instance_node.index_template_node.index)
|
||||
}
|
||||
|
||||
|
||||
def get_breadcrumbs(index_instance, simple=False, single_link=False, include_count=False):
|
||||
"""
|
||||
Return a joined string of HTML anchors to every index instance's
|
||||
parent from the root of the tree to the index instance
|
||||
"""
|
||||
result = []
|
||||
if single_link:
|
||||
# Return the entire breadcrumb path as a single HTML anchor
|
||||
simple = True
|
||||
|
||||
#result.append(get_instance_link(index_instance.get_root(), simple=simple))
|
||||
|
||||
for instance in index_instance.get_ancestors():
|
||||
result.append(get_instance_link(instance, simple=simple))
|
||||
|
||||
result.append(get_instance_link(index_instance, simple=simple))
|
||||
|
||||
output = []
|
||||
|
||||
if include_count:
|
||||
output.append(u'(%d)' % index_instance.documents.count())
|
||||
|
||||
if single_link:
|
||||
# Return the entire breadcrumb path as a single HTML anchor
|
||||
output.insert(0, get_instance_link(index_instance_node=index_instance, text=(u' / '.join(result))))
|
||||
return mark_safe(u' '.join(output))
|
||||
else:
|
||||
output.insert(0, u' / '.join(result))
|
||||
return mark_safe(u' '.join(output))
|
||||
|
||||
|
||||
def do_rebuild_all_indexes():
|
||||
fs_delete_directory_recusive()
|
||||
IndexInstanceNone.objects.delete()
|
||||
|
||||
@@ -21,9 +21,9 @@ from acls.utils import apply_default_acls
|
||||
|
||||
from .forms import IndexForm, IndexTemplateNodeForm
|
||||
from .models import (Index, IndexTemplateNode, IndexInstanceNode)
|
||||
from .api import (get_breadcrumbs, get_instance_link,
|
||||
do_rebuild_all_indexes)
|
||||
from .widgets import index_instance_item_link
|
||||
from .api import do_rebuild_all_indexes
|
||||
from .widgets import (index_instance_item_link, get_instance_link,
|
||||
get_breadcrumbs)
|
||||
from .permissions import (PERMISSION_DOCUMENT_INDEXING_VIEW,
|
||||
PERMISSION_DOCUMENT_INDEXING_REBUILD_INDEXES,
|
||||
PERMISSION_DOCUMENT_INDEXING_SETUP,
|
||||
|
||||
@@ -22,3 +22,52 @@ def index_instance_item_link(index_instance_item):
|
||||
'icon_template': icon_template,
|
||||
'text': index_instance_item
|
||||
})
|
||||
|
||||
|
||||
def get_instance_link(index_instance_node, text=None, simple=False):
|
||||
"""
|
||||
Return an HTML anchor to an index instance
|
||||
"""
|
||||
|
||||
if simple:
|
||||
# Just display the instance's value or overrided text, no
|
||||
# HTML anchor
|
||||
template = u'%(value)s'
|
||||
else:
|
||||
template = u'<a href="%(url)s">%(value)s</a>'
|
||||
|
||||
return template % {
|
||||
'url': index_instance_node.get_absolute_url(),
|
||||
'value': text if text else (index_instance_node if index_instance_node.parent else index_instance_node.index_template_node.index)
|
||||
}
|
||||
|
||||
|
||||
def get_breadcrumbs(index_instance, simple=False, single_link=False, include_count=False):
|
||||
"""
|
||||
Return a joined string of HTML anchors to every index instance's
|
||||
parent from the root of the tree to the index instance
|
||||
"""
|
||||
result = []
|
||||
if single_link:
|
||||
# Return the entire breadcrumb path as a single HTML anchor
|
||||
simple = True
|
||||
|
||||
#result.append(get_instance_link(index_instance.get_root(), simple=simple))
|
||||
|
||||
for instance in index_instance.get_ancestors():
|
||||
result.append(get_instance_link(instance, simple=simple))
|
||||
|
||||
result.append(get_instance_link(index_instance, simple=simple))
|
||||
|
||||
output = []
|
||||
|
||||
if include_count:
|
||||
output.append(u'(%d)' % index_instance.documents.count())
|
||||
|
||||
if single_link:
|
||||
# Return the entire breadcrumb path as a single HTML anchor
|
||||
output.insert(0, get_instance_link(index_instance_node=index_instance, text=(u' / '.join(result))))
|
||||
return mark_safe(u' '.join(output))
|
||||
else:
|
||||
output.insert(0, u' / '.join(result))
|
||||
return mark_safe(u' '.join(output))
|
||||
|
||||
Reference in New Issue
Block a user