Refactor diagnostics app
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user