Refactored the tools menu and added method for apps to register tools themselves
This commit is contained in:
@@ -4,7 +4,7 @@ from django.conf import settings
|
|||||||
|
|
||||||
from navigation.api import register_links, register_menu, \
|
from navigation.api import register_links, register_menu, \
|
||||||
register_model_list_columns, register_multi_item_links
|
register_model_list_columns, register_multi_item_links
|
||||||
from main.api import register_diagnostic
|
from main.api import register_diagnostic, register_tool
|
||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
|
|
||||||
from documents.models import Document, DocumentPage, DocumentPageTransformation
|
from documents.models import Document, DocumentPage, DocumentPageTransformation
|
||||||
@@ -48,7 +48,7 @@ document_multiple_edit_metadata = {'text': _(u'edit metadata'), 'view': 'documen
|
|||||||
document_preview = {'text': _(u'preview'), 'class': 'fancybox', 'view': 'document_preview', 'args': 'object.id', 'famfam': 'magnifier', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}}
|
document_preview = {'text': _(u'preview'), 'class': 'fancybox', 'view': 'document_preview', 'args': 'object.id', 'famfam': 'magnifier', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}}
|
||||||
document_download = {'text': _(u'download'), 'view': 'document_download', 'args': 'object.id', 'famfam': 'page_save', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}}
|
document_download = {'text': _(u'download'), 'view': 'document_download', 'args': 'object.id', 'famfam': 'page_save', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}}
|
||||||
document_find_duplicates = {'text': _(u'find duplicates'), 'view': 'document_find_duplicates', 'args': 'object.id', 'famfam': 'page_refresh', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}}
|
document_find_duplicates = {'text': _(u'find duplicates'), 'view': 'document_find_duplicates', 'args': 'object.id', 'famfam': 'page_refresh', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}}
|
||||||
document_find_all_duplicates = {'text': _(u'find all duplicates'), 'view': 'document_find_all_duplicates', 'famfam': 'page_refresh', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}}
|
document_find_all_duplicates = {'text': _(u'find all duplicates'), 'view': 'document_find_all_duplicates', 'famfam': 'page_refresh', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}, 'description': _(u'Search all the documents\' checksums and return a list of the exact matches.')}
|
||||||
document_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_clear_transformations', 'args': 'object.id', 'famfam': 'page_paintbrush', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}}
|
document_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_clear_transformations', 'args': 'object.id', 'famfam': 'page_paintbrush', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}}
|
||||||
document_multiple_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}}
|
document_multiple_clear_transformations = {'text': _(u'clear all transformations'), 'view': 'document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}}
|
||||||
|
|
||||||
@@ -115,6 +115,7 @@ register_links(['metadatagroup_view'], [metadata_group_back_to_document, metadat
|
|||||||
|
|
||||||
register_diagnostic('documents', _(u'Documents'), document_missing_list)
|
register_diagnostic('documents', _(u'Documents'), document_missing_list)
|
||||||
|
|
||||||
|
register_tool(document_find_all_duplicates, namespace='documents', title=_(u'documents'))
|
||||||
|
|
||||||
def document_exists(document):
|
def document_exists(document):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
|
|
||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
|
from main.api import register_tool
|
||||||
|
|
||||||
|
|
||||||
FILESYSTEM_SERVING_RECREATE_LINKS = 'recreate_links'
|
FILESYSTEM_SERVING_RECREATE_LINKS = 'recreate_links'
|
||||||
@@ -10,5 +11,6 @@ register_permissions('filesystem_serving', [
|
|||||||
{'name': FILESYSTEM_SERVING_RECREATE_LINKS, 'label':_(u'Recreate filesystem links.')},
|
{'name': FILESYSTEM_SERVING_RECREATE_LINKS, 'label':_(u'Recreate filesystem links.')},
|
||||||
])
|
])
|
||||||
|
|
||||||
|
filesystem_serving_recreate_all_links = {'text': _('recreate index links'), 'view': 'recreate_all_links', 'famfam': 'page_link', 'permissions': {'namespace': 'filesystem_serving', 'permissions': [FILESYSTEM_SERVING_RECREATE_LINKS]}, 'description': _(u'Deletes and creates from scratch all the file system indexing links.')}
|
||||||
|
|
||||||
filesystem_serving_recreate_all_links = {'text': _('recreate index links'), 'view': 'recreate_all_links', 'famfam': 'page_link', 'permissions': {'namespace': 'filesystem_serving', 'permissions': [FILESYSTEM_SERVING_RECREATE_LINKS]}}
|
register_tool(filesystem_serving_recreate_all_links, namespace='filesystem_serving', title=_(u'Filesystem'))
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ from main.conf.settings import SIDE_BAR_SEARCH
|
|||||||
check_settings = {'text': _(u'settings'), 'view': 'check_settings', 'famfam': 'cog'}
|
check_settings = {'text': _(u'settings'), 'view': 'check_settings', 'famfam': 'cog'}
|
||||||
statistics = {'text': _(u'statistics'), 'view': 'statistics', 'famfam': 'table'}
|
statistics = {'text': _(u'statistics'), 'view': 'statistics', 'famfam': 'table'}
|
||||||
diagnostics = {'text': _(u'diagnostics'), 'view': 'diagnostics', 'famfam': 'pill'}
|
diagnostics = {'text': _(u'diagnostics'), 'view': 'diagnostics', 'famfam': 'pill'}
|
||||||
|
tools = {'text': _(u'tools'), 'view': 'tools_menu', 'famfam': 'wrench'}
|
||||||
|
admin_site = {'text': _(u'admin site'), 'url': '/admin', 'famfam': 'keyboard'}
|
||||||
|
sentry = {'text': _(u'sentry'), 'url': '/sentry', 'famfam': 'bug'}
|
||||||
|
|
||||||
__version_info__ = {
|
__version_info__ = {
|
||||||
'major': 0,
|
'major': 0,
|
||||||
@@ -23,6 +26,25 @@ __version_info__ = {
|
|||||||
'serial': 0
|
'serial': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_menu = [
|
||||||
|
{'text': _(u'home'), 'view': 'home', 'famfam': 'house', 'position': 0},
|
||||||
|
{'text': _(u'tools'), 'view': 'tools_menu', 'links': [
|
||||||
|
tools, statistics, diagnostics, sentry
|
||||||
|
], 'famfam': 'wrench', 'name': 'tools', 'position': 7},
|
||||||
|
|
||||||
|
{'text': _(u'setup'), 'view': 'check_settings', 'links': [
|
||||||
|
check_settings, role_list, user_list, admin_site
|
||||||
|
], 'famfam': 'cog', 'name': 'setup', 'position': 8},
|
||||||
|
|
||||||
|
{'text': _(u'about'), 'view': 'about', 'position': 9},
|
||||||
|
]
|
||||||
|
|
||||||
|
if not SIDE_BAR_SEARCH:
|
||||||
|
main_menu.insert(1, {'text': _(u'search'), 'view': 'search', 'famfam': 'zoom', 'position': 2})
|
||||||
|
|
||||||
|
register_menu(main_menu)
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
"""
|
"""
|
||||||
Return the formatted version information
|
Return the formatted version information
|
||||||
@@ -36,23 +58,3 @@ def get_version():
|
|||||||
return ''.join(vers)
|
return ''.join(vers)
|
||||||
|
|
||||||
__version__ = get_version()
|
__version__ = get_version()
|
||||||
|
|
||||||
|
|
||||||
main_menu = [
|
|
||||||
{'text': _(u'home'), 'view': 'home', 'famfam': 'house', 'position': 0},
|
|
||||||
{'text': _(u'tools'), 'view': 'tools_menu', 'links': [
|
|
||||||
document_find_all_duplicates, filesystem_serving_recreate_all_links,
|
|
||||||
all_document_ocr_cleanup, statistics, diagnostics,
|
|
||||||
], 'famfam': 'wrench', 'name': 'tools', 'position': 7},
|
|
||||||
|
|
||||||
{'text': _(u'setup'), 'view': 'check_settings', 'links': [
|
|
||||||
check_settings, role_list, user_list
|
|
||||||
], 'famfam': 'cog', 'name': 'setup', 'position': 8},
|
|
||||||
|
|
||||||
{'text': _(u'about'), 'view': 'about', 'position': 9},
|
|
||||||
]
|
|
||||||
|
|
||||||
if not SIDE_BAR_SEARCH:
|
|
||||||
main_menu.insert(1, {'text': _(u'search'), 'view': 'search', 'famfam': 'zoom', 'position': 2})
|
|
||||||
|
|
||||||
register_menu(main_menu)
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.utils.functional import lazy
|
||||||
|
|
||||||
diagnostics = {}
|
diagnostics = {}
|
||||||
|
tools = {}
|
||||||
|
reverse_lazy = lazy(reverse, str)
|
||||||
|
|
||||||
|
|
||||||
def register_diagnostic(namespace, title, link):
|
def register_diagnostic(namespace, title, link):
|
||||||
@@ -9,3 +12,11 @@ def register_diagnostic(namespace, title, link):
|
|||||||
link['url'] = link.get('url', reverse(link['view']))
|
link['url'] = link.get('url', reverse(link['view']))
|
||||||
namespace_dict['links'].append(link)
|
namespace_dict['links'].append(link)
|
||||||
diagnostics[namespace] = namespace_dict
|
diagnostics[namespace] = namespace_dict
|
||||||
|
|
||||||
|
|
||||||
|
def register_tool(link, title=None, namespace=None):
|
||||||
|
namespace_dict = tools.get(namespace, {'title': None, 'links': []})
|
||||||
|
namespace_dict['title'] = title
|
||||||
|
link['url'] = link.get('url', reverse_lazy(link['view']))
|
||||||
|
namespace_dict['links'].append(link)
|
||||||
|
tools[namespace] = namespace_dict
|
||||||
|
|||||||
22
apps/main/templates/tools.html
Normal file
22
apps/main/templates/tools.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %} :: {{ title|capfirst }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% for key, value in blocks.items %}
|
||||||
|
<div class="content">
|
||||||
|
<h2 class="title">{{ value.title|capfirst }}</h2>
|
||||||
|
<div class="inner">
|
||||||
|
<p>
|
||||||
|
<ul class="undecorated_list">
|
||||||
|
{% for link in value.links %}
|
||||||
|
<li>
|
||||||
|
{% include "generic_subnavigation.html" %}{% if link.description %} - {{ link.description }}{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div></div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
@@ -13,7 +13,7 @@ from filesystem_serving.conf import settings as filesystem_serving_settings
|
|||||||
from dynamic_search.conf import settings as search_settings
|
from dynamic_search.conf import settings as search_settings
|
||||||
|
|
||||||
from main.conf import settings as main_settings
|
from main.conf import settings as main_settings
|
||||||
from main.api import diagnostics
|
from main.api import diagnostics, tools
|
||||||
|
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
@@ -116,19 +116,13 @@ def check_settings(request):
|
|||||||
return render_to_response('generic_list.html', context,
|
return render_to_response('generic_list.html', context,
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def tools_menu(request):
|
def tools_menu(request):
|
||||||
return render_to_response('generic_template.html', {
|
return render_to_response('tools.html', {
|
||||||
'title': _(u'Tools menu'),
|
'blocks': tools,
|
||||||
'paragraphs': [
|
'title': _(u'tools menu')
|
||||||
_(u'"Find all duplicates": Search all the documents\' checksums and return a list of the exact matches.'),
|
|
||||||
_(u'"Recreate index links": Deletes and creates from scratch all the file system indexing links.'),
|
|
||||||
_(u'"Clean up pages content": Runs a language filter to remove common OCR mistakes from document pages content.')
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def statistics(request):
|
def statistics(request):
|
||||||
blocks = []
|
blocks = []
|
||||||
blocks.append(documents_statistics())
|
blocks.append(documents_statistics())
|
||||||
|
|||||||
1
apps/navigation/templates/generic_link_instance.html
Normal file
1
apps/navigation/templates/generic_link_instance.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<a class="{{ link.class }}" href="{{ link.url }}">{% if link.famfam %}<span class="famfam active famfam-{{ link.famfam|default:'link' }}"></span>{% endif %}{{ link.text|capfirst }}{% if link.error %} - {{ link.error }}{% endif %}{% if link.active %}<span class="famfam active famfam-resultset_previous"></span>{% endif %}</a>{% if horizontal %}{% if not forloop.last %} | {% endif %}{% endif %}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
{% load permission_tags %}
|
|
||||||
|
|
||||||
<span class="nowrap">
|
<span class="nowrap">
|
||||||
{% for link in object_navigation_links %}
|
{% for link in object_navigation_links %}
|
||||||
{% if link.permissions %}
|
{% include "generic_subnavigation.html" %}
|
||||||
{% check_permissions request.user link.permissions.namespace link.permissions.permissions %}
|
|
||||||
{% if permission %}
|
|
||||||
{% if as_li %}<li>{% endif %}
|
|
||||||
<a class="{{ link.class }}" href="{{ link.url }}">{% if link.famfam %}<span class="famfam active famfam-{{ link.famfam|default:'link' }}"></span>{% endif %}{{ link.text|capfirst }}{% if link.error %} - {{ link.error }}{% endif %}{% if link.active %}<span class="famfam active famfam-resultset_previous"></span>{% endif %}</a>{% if horizontal %}{% if not forloop.last %} | {% endif %}{% endif %}
|
|
||||||
{% if as_li %}</li>{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
{% if as_li %}<li>{% endif %}
|
|
||||||
<a class="{{ link.class }}" href="{{ link.url }}">{% if link.famfam %}<span class="famfam active famfam-{{ link.famfam|default:'link' }}"></span>{% endif %}{{ link.text|capfirst }}{% if link.error %} - {{ link.error }}{% endif %}{% if link.active %}<span class="famfam active famfam-resultset_previous"></span>{% endif %}</a>{% if horizontal %}{% if not forloop.last %} | {% endif %}{% endif %}
|
|
||||||
{% if as_li %}</li>{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
14
apps/navigation/templates/generic_subnavigation.html
Normal file
14
apps/navigation/templates/generic_subnavigation.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{% load permission_tags %}
|
||||||
|
|
||||||
|
{% if link.permissions %}
|
||||||
|
{% check_permissions request.user link.permissions.namespace link.permissions.permissions %}
|
||||||
|
{% if permission %}
|
||||||
|
{% if as_li %}<li>{% endif %}
|
||||||
|
{% include "generic_link_instance.html" %}
|
||||||
|
{% if as_li %}</li>{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{% if as_li %}<li>{% endif %}
|
||||||
|
{% include "generic_link_instance.html" %}
|
||||||
|
{% if as_li %}</li>{% endif %}
|
||||||
|
{% endif %}
|
||||||
@@ -2,13 +2,16 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
from navigation.api import register_links, register_menu, register_multi_item_links
|
from navigation.api import register_links, register_menu, register_multi_item_links
|
||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
|
from main.api import register_tool
|
||||||
|
|
||||||
from ocr.conf.settings import AUTOMATIC_OCR
|
from ocr.conf.settings import AUTOMATIC_OCR
|
||||||
from ocr.models import DocumentQueue
|
from ocr.models import DocumentQueue
|
||||||
|
from ocr.urls import urlpatterns
|
||||||
|
|
||||||
#Permissions
|
#Permissions
|
||||||
PERMISSION_OCR_DOCUMENT = 'ocr_document'
|
PERMISSION_OCR_DOCUMENT = 'ocr_document'
|
||||||
@@ -33,7 +36,7 @@ queue_document_multiple_delete = {'text': _(u'delete'), 'view': 'queue_document_
|
|||||||
document_queue_disable = {'text': _(u'stop queue'), 'view': 'document_queue_disable', 'args': 'object.id', 'famfam': 'control_stop_blue', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_QUEUE_ENABLE_DISABLE]}}
|
document_queue_disable = {'text': _(u'stop queue'), 'view': 'document_queue_disable', 'args': 'object.id', 'famfam': 'control_stop_blue', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_QUEUE_ENABLE_DISABLE]}}
|
||||||
document_queue_enable = {'text': _(u'activate queue'), 'view': 'document_queue_enable', 'args': 'object.id', 'famfam': 'control_play_blue', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_QUEUE_ENABLE_DISABLE]}}
|
document_queue_enable = {'text': _(u'activate queue'), 'view': 'document_queue_enable', 'args': 'object.id', 'famfam': 'control_play_blue', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_QUEUE_ENABLE_DISABLE]}}
|
||||||
|
|
||||||
all_document_ocr_cleanup = {'text': _(u'clean up pages content'), 'view': 'all_document_ocr_cleanup', 'famfam': 'text_strikethrough', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_CLEAN_ALL_PAGES]}}
|
all_document_ocr_cleanup = {'text': _(u'clean up pages content'), 'view': 'all_document_ocr_cleanup', 'famfam': 'text_strikethrough', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_CLEAN_ALL_PAGES]}, 'description': _(u'Runs a language filter to remove common OCR mistakes from document pages content.')}
|
||||||
|
|
||||||
queue_document_list = {'text': _(u'queue document list'), 'view': 'queue_document_list', 'famfam': 'hourglass', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_DOCUMENT]}}
|
queue_document_list = {'text': _(u'queue document list'), 'view': 'queue_document_list', 'famfam': 'hourglass', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_DOCUMENT]}}
|
||||||
node_active_list = {'text': _(u'active tasks'), 'view': 'node_active_list', 'famfam': 'server_chart', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_DOCUMENT]}}
|
node_active_list = {'text': _(u'active tasks'), 'view': 'node_active_list', 'famfam': 'server_chart', 'permissions': {'namespace': 'ocr', 'permissions': [PERMISSION_OCR_DOCUMENT]}}
|
||||||
@@ -43,6 +46,8 @@ register_links(DocumentQueue, [document_queue_disable, document_queue_enable])
|
|||||||
|
|
||||||
register_multi_item_links(['queue_document_list'], [re_queue_multiple_document, queue_document_multiple_delete])
|
register_multi_item_links(['queue_document_list'], [re_queue_multiple_document, queue_document_multiple_delete])
|
||||||
|
|
||||||
|
register_tool(all_document_ocr_cleanup, namespace='ocr', title=_(u'OCR'))
|
||||||
|
|
||||||
#Menus
|
#Menus
|
||||||
register_menu([
|
register_menu([
|
||||||
{'text': _('OCR'), 'view': 'queue_document_list', 'links':[
|
{'text': _('OCR'), 'view': 'queue_document_list', 'links':[
|
||||||
|
|||||||
Reference in New Issue
Block a user