Refactor diagnostics app
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from project_tools.api import register_tool
|
||||
from navigation.api import bind_links
|
||||
|
||||
from .links import diagnostics
|
||||
from .links import diagnostic_list, diagnostic_execute
|
||||
from .api import DiagnosticTool
|
||||
|
||||
register_tool(diagnostics)
|
||||
register_tool(diagnostic_list)
|
||||
bind_links(['diagnostic_list'], diagnostic_list, menu_name='secondary_menu')
|
||||
bind_links([DiagnosticTool], diagnostic_execute)
|
||||
|
||||
@@ -1,11 +1,55 @@
|
||||
from common.utils import reverse_lazy
|
||||
from navigation.api import bind_links
|
||||
|
||||
diagnostics = {}
|
||||
from .links import diagnostic_list
|
||||
|
||||
tools = {}
|
||||
|
||||
|
||||
def register_diagnostic(namespace, title, link):
|
||||
namespace_dict = diagnostics.get(namespace, {'title': None, 'links': []})
|
||||
namespace_dict['title'] = title
|
||||
link.url = getattr(link, 'url', reverse_lazy(link.view))
|
||||
namespace_dict['links'].append(link)
|
||||
diagnostics[namespace] = namespace_dict
|
||||
class DiagnosticNamespace(object):
|
||||
namespaces = {}
|
||||
tools_by_id = {}
|
||||
|
||||
@classmethod
|
||||
def tool_all(cls):
|
||||
tool_list = []
|
||||
for namespace in cls.all():
|
||||
for tool in namespace.tools:
|
||||
tool_list.append(tool)
|
||||
|
||||
return tool_list
|
||||
|
||||
@classmethod
|
||||
def tool_get(cls, id):
|
||||
return DiagnosticNamespace.tools_by_id[id]
|
||||
|
||||
@classmethod
|
||||
def all(cls):
|
||||
return DiagnosticNamespace.namespaces.keys()
|
||||
|
||||
def __init__(self, label):
|
||||
self.label = label
|
||||
self.tools = []
|
||||
DiagnosticNamespace.namespaces[self] = self
|
||||
|
||||
def create_tool(self, link):
|
||||
tool = DiagnosticTool(self, link)
|
||||
self.add_tool(tool)
|
||||
return tool
|
||||
|
||||
def add_tool(self, tool_instance):
|
||||
self.tools.append(tool_instance)
|
||||
tool_instance.id = len(DiagnosticNamespace.tools_by_id) + 1
|
||||
DiagnosticNamespace.tools_by_id[tool_instance.id] = tool_instance
|
||||
bind_links([tool_instance.link.view], diagnostic_list, menu_name='secondary_menu')
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.label)
|
||||
|
||||
|
||||
class DiagnosticTool(object):
|
||||
def __init__(self, namespace, link):
|
||||
self.namespace = namespace
|
||||
self.link = link
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.link.text)
|
||||
|
||||
@@ -4,4 +4,5 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import Link
|
||||
|
||||
diagnostics = Link(text=_(u'diagnostics'), view='diagnostics', sprite='pill', icon='pill.png')
|
||||
diagnostic_list = Link(text=_(u'diagnostics'), view='diagnostic_list', icon='pill.png', sprite='pill')
|
||||
diagnostic_execute = Link(text=_(u'execute'), view='diagnostic_execute', args='object.id', sprite='lightning')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
urlpatterns = patterns('diagnostics.views',
|
||||
url(r'^$', 'diagnostics_view', (), 'diagnostics'),
|
||||
url(r'^$', 'diagnostic_list', (), 'diagnostic_list'),
|
||||
url(r'^execute/(?P<diagnostic_tool_id>\w+)/$', 'diagnostic_execute', (), 'diagnostic_execute'),
|
||||
)
|
||||
|
||||
@@ -1,15 +1,43 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.text import capfirst
|
||||
|
||||
from .api import diagnostics
|
||||
from common.utils import encapsulate
|
||||
from permissions.models import Permission
|
||||
|
||||
from .api import DiagnosticNamespace
|
||||
|
||||
|
||||
def diagnostics_view(request):
|
||||
return render_to_response('diagnostics.html', {
|
||||
'blocks': diagnostics,
|
||||
'title': _(u'Diagnostics')
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
def diagnostic_list(request):
|
||||
tool_list = []
|
||||
|
||||
for tool in DiagnosticNamespace.tool_all():
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, tool.link.permissions)
|
||||
except PermissionDenied:
|
||||
pass
|
||||
else:
|
||||
tool_list.append(tool)
|
||||
|
||||
return render_to_response('generic_list.html', {
|
||||
'title': _(u'diagnostic tools'),
|
||||
'object_list': tool_list,
|
||||
'extra_columns': [
|
||||
{'name': _(u'namespace'), 'attribute': encapsulate(lambda x: capfirst(x.namespace))},
|
||||
{'name': _(u'label'), 'attribute': encapsulate(lambda x: capfirst(x.link.text))},
|
||||
{'name': _(u'description'), 'attribute': 'link.description'},
|
||||
],
|
||||
'hide_object': True,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def diagnostic_execute(request, diagnostic_tool_id):
|
||||
tool = DiagnosticNamespace.tool_get(int(diagnostic_tool_id))
|
||||
context = RequestContext(request)
|
||||
resolve_link = tool.link.resolve(context)
|
||||
return HttpResponseRedirect(resolve_link.url)
|
||||
|
||||
@@ -8,7 +8,7 @@ from common.utils import validate_path, encapsulate
|
||||
from navigation.api import (bind_links, register_top_menu,
|
||||
register_model_list_columns,
|
||||
register_sidebar_template, Link, register_multi_item_links)
|
||||
from diagnostics.api import register_diagnostic
|
||||
from diagnostics.api import DiagnosticNamespace
|
||||
from maintenance.api import MaintenanceNamespace
|
||||
from history.permissions import PERMISSION_HISTORY_VIEW
|
||||
from project_setup.api import register_setup
|
||||
@@ -85,7 +85,8 @@ bind_links('document_page_transformation_list', [document_page_transformation_cr
|
||||
bind_links('document_page_transformation_create', [document_page_transformation_create], menu_name='sidebar')
|
||||
bind_links(['document_page_transformation_edit', 'document_page_transformation_delete'], [document_page_transformation_create], menu_name='sidebar')
|
||||
|
||||
register_diagnostic('documents', _(u'Documents'), document_missing_list)
|
||||
namespace = DiagnosticNamespace(_(u'documents'))
|
||||
namespace.create_tool(document_missing_list)
|
||||
|
||||
namespace = MaintenanceNamespace(_(u'documents'))
|
||||
namespace.create_tool(document_find_all_duplicates)
|
||||
|
||||
@@ -57,7 +57,7 @@ document_clear_transformations = Link(text=_(u'clear transformations'), view='do
|
||||
document_multiple_clear_transformations = Link(text=_(u'clear transformations'), view='document_multiple_clear_transformations', sprite='page_paintbrush', permissions=[PERMISSION_DOCUMENT_TRANSFORM])
|
||||
document_print = Link(text=_(u'print'), view='document_print', args='object.id', sprite='printer', permissions=[PERMISSION_DOCUMENT_VIEW])
|
||||
document_history_view = Link(text=_(u'history'), view='history_for_object', args=['"documents"', '"document"', 'object.pk'], sprite='book_go', permissions=[PERMISSION_HISTORY_VIEW])
|
||||
document_missing_list = Link(text=_(u'Find missing document files'), view='document_missing_list', sprite='folder_page', permissions=[PERMISSION_DOCUMENT_VIEW])
|
||||
document_missing_list = Link(text=_(u'Find missing document files'), view='document_missing_list', sprite='page_find', description=_(u'Return a list of documents found on the database but that don\'t physically exist in the document storage.'), permissions=[PERMISSION_DOCUMENT_VIEW])
|
||||
|
||||
# Tools
|
||||
document_clear_image_cache = Link(text=_(u'Clear the document image cache'), view='document_clear_image_cache', sprite='camera_delete', permissions=[PERMISSION_DOCUMENT_TOOLS], description=_(u'Clear the graphics representations used to speed up the documents\' display and interactive transformations results.'))
|
||||
|
||||
@@ -676,6 +676,7 @@ def document_missing_list(request):
|
||||
return render_to_response('generic_confirm.html', {
|
||||
'previous': previous,
|
||||
'message': _(u'On large databases this operation may take some time to execute.'),
|
||||
'form_icon': 'page_find.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
else:
|
||||
missing_id_list = []
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
{% 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">
|
||||
{% with value.links as object_navigation_links %}
|
||||
{% with 'true' as as_li %}
|
||||
{% include "generic_navigation.html" %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
</div></div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user