refactor multi-controller dashboard (nagios)
diff --git a/xos/core/dashboard/views/home.py b/xos/core/dashboard/views/home.py
index 052cc21..bc721f0 100644
--- a/xos/core/dashboard/views/home.py
+++ b/xos/core/dashboard/views/home.py
@@ -41,12 +41,8 @@
TEMPLATE_DIRS = [XOS_DIR + "/templates/admin/dashboard/",
XOS_DIR + "/core/xoslib/dashboards/"]
- # starting from the ID loading the template name
- current_dasboard = DashboardView.objects.filter(id=fn)
- template_url = current_dasboard[0].url.replace("template:",'')
-
for template_dir in TEMPLATE_DIRS:
- pathname = os.path.join(template_dir, template_url) + ".html"
+ pathname = os.path.join(template_dir, fn) + ".html"
if os.path.exists(pathname):
break
else:
@@ -58,7 +54,7 @@
template = '<div id="tabs-5"></div>' + template
return template
- def embedDashboard(self, url):
+ def embedDashboardUrl(self, url):
if url.startswith("template:"):
fn = url[9:]
return self.readTemplate(fn)
@@ -67,6 +63,37 @@
else:
return "don't know how to load dashboard %s" % url
+ def embedDashboardView(self, view, i=0):
+ body = ""
+ url = view.url
+ if (view.controllers.all().count()>0):
+ body = body + 'Controller: <select id="dashselect-%d">' % i;
+ body = body + '<option value="None">(select a controller)</option>';
+ for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
+ body = body + '<option value="%d">%s</option>' % (j, controllerdashboard.controller.name)
+ body = body + '</select><hr>'
+
+ for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
+ body = body + '<script type="text/template" id="dashtemplate-%d-%d">\n%s\n</script>\n' % (i,j, self.embedDashboardUrl(controllerdashboard.url));
+
+ body = body + '<div id="dashcontent-%d" class="dashcontent"></div>\n' % i
+
+ body = body + """<script>
+ $("#dashselect-%d").change(function() {
+ v=$("#dashselect-%d").val();
+ if (v=="None") {
+ $("#dashcontent-%d").html("");
+ return;
+ }
+ $("#dashcontent-%d").html( $("#dashtemplate-%d-" + v).html() );
+ });
+ //$("#dashcontent-%d").html( $("#dashtemplate-%d-0").html() );
+ </script>
+ """ % (i,i,i,i,i,i,i);
+ else:
+ body = body + self.embedDashboardUrl(url)
+ return body
+
def multiDashboardView(self, request, context):
head_template = self.head_template
tail_template = self.tail_template
@@ -89,38 +116,7 @@
continue
tabs.append( '<li><a href="#dashtab-%d">%s</a></li>\n' % (i, view.name) )
-
- body = ""
-
- url = view.url
- body = body + '<div id="dashtab-%d">\n' % i
- if (view.controllers.all().count()>0):
- body = body + 'Controller: <select id="dashselect-%d">' % i;
- body = body + '<option value="None">(select a controller)</option>';
- for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
- body = body + '<option value="%d">%s</option>' % (j, controllerdashboard.controller.name)
- body = body + '</select><hr>'
-
- for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
- body = body + '<script type="text/template" id="dashtemplate-%d-%d">\n%s\n</script>\n' % (i,j, self.embedDashboard(controllerdashboard.url));
-
- body = body + '<div id="dashcontent-%d" class="dashcontent"></div>\n' % i
-
- body = body + """<script>
- $("#dashselect-%d").change(function() {
- v=$("#dashselect-%d").val();
- if (v=="None") {
- $("#dashcontent-%d").html("");
- return;
- }
- $("#dashcontent-%d").html( $("#dashtemplate-%d-" + v).html() );
- });
- //$("#dashcontent-%d").html( $("#dashtemplate-%d-0").html() );
- </script>
- """ % (i,i,i,i,i,i,i);
- else:
- body = body + self.embedDashboard(url)
- body = body + '</div>\n'
+ body = '<div id="dashtab-%d">%s</div>\n' % (i, self.embedDashboardView(view, i))
bodies.append(body)
i = i + 1
@@ -132,7 +128,7 @@
body = ""
body = body + '<div id="dashtab-%d">\n' % i
- body = body + self.embedDashboard("http:/admin/hpc/contentprovider/%s/%s/embeddedfilteredchange" % (cp.serviceProvider.hpcService.id, cp.id))
+ body = body + self.embedDashboardUrl("http:/admin/hpc/contentprovider/%s/%s/embeddedfilteredchange" % (cp.serviceProvider.hpcService.id, cp.id))
body = body + '</div>\n'
bodies.append(body)
@@ -161,13 +157,15 @@
context = context,
**response_kwargs)
- def singleDashboardView(self, request, name, context):
+ def singleDashboardView(self, request, id, context):
head_template = self.head_template
tail_template = self.tail_template
- print >>sys.stderr, name
+ view = DashboardView.objects.get(id=id)
- t = template.Template(head_template + self.readTemplate(name) + self.tail_template)
+ print "XXX", view
+
+ t = template.Template(head_template + self.embedDashboardView(view) + self.tail_template)
response_kwargs = {}
response_kwargs.setdefault('content_type', self.content_type)
@@ -177,11 +175,13 @@
context = context,
**response_kwargs)
- def singleFullView(self, request, name, context):
+ def singleFullView(self, request, id, context):
head_template = self.head_wholePage_template
tail_template = self.tail_template
- t = template.Template(head_template + self.readTemplate(name) + self.tail_template)
+ view = DashboardView.objects.get(id=id)
+
+ t = template.Template(head_template + self.embedDashboardView(view) + self.tail_template)
response_kwargs = {}
response_kwargs.setdefault('content_type', self.content_type)