X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fdashboard%2Fviews%2Fhome.py;h=3084c0eca061b0f84da2aefa973ab68a47255188;hb=149befce1a2f20730d6cce5f0b131e1cfc04cd24;hp=06e2c5f9183fadf5ffd496d7cfe9f9472f837cc8;hpb=c7325a4cab484ecff9927fbfc479e8d5ad1a5351;p=plstackapi.git diff --git a/planetstack/core/dashboard/views/home.py b/planetstack/core/dashboard/views/home.py index 06e2c5f..3084c0e 100644 --- a/planetstack/core/dashboard/views/home.py +++ b/planetstack/core/dashboard/views/home.py @@ -14,6 +14,11 @@ class DashboardDynamicView(TemplateView): {% block content %} """ + head_wholePage_template = r"""{% extends "admin/wholePage.html" %} + {% load admin_static %} + {% block content %} + """ + tail_template = r"{% endblock %}" def get(self, request, name="root", *args, **kwargs): @@ -22,18 +27,36 @@ class DashboardDynamicView(TemplateView): if name=="root": return self.multiDashboardView(request, context) + elif kwargs.get("wholePage",None): + return self.singleFullView(request, name, context) else: return self.singleDashboardView(request, name, context) - def readDashboard(self, fn): - try: - template= open("/opt/planetstack/templates/admin/dashboard/%s.html" % fn, "r").read() - if (fn=="tenant"): - # fix for tenant view - it writes html to a div called tabs-5 - template = '
' + template - return template - except: - return "failed to open %s" % fn + def readTemplate(self, fn): + TEMPLATE_DIRS = ["/opt/planetstack/templates/admin/dashboard/", + "/opt/planetstack/core/xoslib/dashboards/"] + + for template_dir in TEMPLATE_DIRS: + pathname = os.path.join(template_dir, fn) + ".html" + if os.path.exists(pathname): + break + else: + return "failed to find %s in %s" % (fn, TEMPLATE_DIRS) + + template= open(pathname, "r").read() + if (fn=="tenant"): + # fix for tenant view - it writes html to a div called tabs-5 + template = '
' + template + return template + + def embedDashboard(self, url): + if url.startswith("template:"): + fn = url[9:] + return self.readTemplate(fn) + elif url.startswith("http"): + return '' % url + else: + return "don't know how to load dashboard %s" % url def multiDashboardView(self, request, context): head_template = self.head_template @@ -52,16 +75,46 @@ class DashboardDynamicView(TemplateView): dashboards.append(customize[0]) for i,view in enumerate(dashboards): + # don't display disabled dashboards + if (not view.enabled): + continue body = body + '
  • %s
  • \n' % (i, view.name) body = body + "\n" for i,view in enumerate(dashboards): + # don't display disabled dashboards + if (not view.enabled): + continue + url = view.url body = body + '
    \n' % i - if url.startswith("template:"): - fn = url[9:] - body = body + self.readDashboard(fn) + if (view.controllers.all().count()>0): + body = body + 'Controller:
    ' + + for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()): + body = body + '\n' % (i,j, self.embedDashboard(controllerdashboard.url)); + + body = body + '
    \n' % i + + body = body + """ + """ % (i,i,i,i,i,i,i); + else: + body = body + self.embedDashboard(url) body = body + '
    \n' body=body+"\n" @@ -80,7 +133,21 @@ class DashboardDynamicView(TemplateView): head_template = self.head_template tail_template = self.tail_template - t = template.Template(head_template + self.readDashboard(name) + self.tail_template) + t = template.Template(head_template + self.readTemplate(name) + self.tail_template) + + response_kwargs = {} + response_kwargs.setdefault('content_type', self.content_type) + return self.response_class( + request = request, + template = t, + context = context, + **response_kwargs) + + def singleFullView(self, request, name, context): + head_template = self.head_wholePage_template + tail_template = self.tail_template + + t = template.Template(head_template + self.readTemplate(name) + self.tail_template) response_kwargs = {} response_kwargs.setdefault('content_type', self.content_type)