1 from view_common import *
3 class DashboardWelcomeView(TemplateView):
4 template_name = 'admin/dashboard/welcome.html'
6 def get(self, request, *args, **kwargs):
7 context = self.get_context_data(**kwargs)
8 context = getDashboardContext(request.user, context)
9 return self.render_to_response(context=context)
11 class DashboardDynamicView(TemplateView):
12 head_template = r"""{% extends "admin/dashboard/dashboard_base.html" %}
13 {% load admin_static %}
17 head_wholePage_template = r"""{% extends "admin/wholePage.html" %}
18 {% load admin_static %}
22 tail_template = r"{% endblock %}"
24 def get(self, request, name="root", *args, **kwargs):
25 context = self.get_context_data(**kwargs)
26 context = getDashboardContext(request.user, context)
29 return self.multiDashboardView(request, context)
30 elif kwargs.get("wholePage",None):
31 return self.singleFullView(request, name, context)
33 return self.singleDashboardView(request, name, context)
35 def readTemplate(self, fn):
36 TEMPLATE_DIRS = ["/opt/planetstack/templates/admin/dashboard/",
37 "/opt/planetstack/core/xoslib/dashboards/"]
39 for template_dir in TEMPLATE_DIRS:
40 pathname = os.path.join(template_dir, fn) + ".html"
41 if os.path.exists(pathname):
44 return "failed to find %s in %s" % (fn, TEMPLATE_DIRS)
46 template= open(pathname, "r").read()
48 # fix for tenant view - it writes html to a div called tabs-5
49 template = '<div id="tabs-5"></div>' + template
52 def embedDashboard(self, url):
53 if url.startswith("template:"):
55 return self.readTemplate(fn)
56 elif url.startswith("http"):
57 return '<iframe src="%s" width="100%%" height="100%%" style="min-height: 1024px;" frameBorder="0"></iframe>' % url
59 return "don't know how to load dashboard %s" % url
61 def multiDashboardView(self, request, context):
62 head_template = self.head_template
63 tail_template = self.tail_template
67 <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
70 dashboards = request.user.get_dashboards()
72 # customize is a special dashboard they always get
73 customize = DashboardView.objects.filter(name="Customize")
75 dashboards.append(customize[0])
77 for i,view in enumerate(dashboards):
78 body = body + '<li><a href="#dashtab-%d">%s</a></li>\n' % (i, view.name)
80 body = body + "</ul>\n"
82 for i,view in enumerate(dashboards):
84 body = body + '<div id="dashtab-%d">\n' % i
85 if (view.controllers.all().count()>0):
86 body = body + '<select id="dashselect-%d">' % i;
87 for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
88 body = body + '<option value="%d">%s</option>' % (j, controllerdashboard.controller.name)
89 body = body + '</select>'
91 for j,controllerdashboard in enumerate(view.controllerdashboardviews.all()):
92 body = body + '<script type="text/template" id="dashtemplate-%d-%d">\n%s\n</script>\n' % (i,j, self.embedDashboard(controllerdashboard.url));
94 body = body + '<div id="dashcontent-%d" class="dashcontent"></div>\n' % i
96 body = body + """<script>
97 $("#dashselect-%d").change(function() {
98 v=$("#dashselect-%d").val();
99 $("#dashcontent-%d").html( $("#dashtemplate-%d-" + v).html() );
101 $("#dashcontent-%d").html( $("#dashtemplate-%d-0").html() );
105 body = body + self.embedDashboard(url)
106 body = body + '</div>\n'
110 t = template.Template(head_template + body + self.tail_template)
113 response_kwargs.setdefault('content_type', self.content_type)
114 return self.response_class(
\r
120 def singleDashboardView(self, request, name, context):
121 head_template = self.head_template
122 tail_template = self.tail_template
124 t = template.Template(head_template + self.readTemplate(name) + self.tail_template)
127 response_kwargs.setdefault('content_type', self.content_type)
128 return self.response_class(
\r
134 def singleFullView(self, request, name, context):
135 head_template = self.head_wholePage_template
136 tail_template = self.tail_template
138 t = template.Template(head_template + self.readTemplate(name) + self.tail_template)
141 response_kwargs.setdefault('content_type', self.content_type)
142 return self.response_class(
\r