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 tail_template = r"{% endblock %}"
19 def get(self, request, name="root", *args, **kwargs):
20 context = self.get_context_data(**kwargs)
21 context = getDashboardContext(request.user, context)
24 return self.multiDashboardView(request, context)
26 return self.singleDashboardView(request, name, context)
28 def readTemplate(self, fn):
30 template= open("/opt/planetstack/templates/admin/dashboard/%s.html" % fn, "r").read()
32 # fix for tenant view - it writes html to a div called tabs-5
33 template = '<div id="tabs-5"></div>' + template
36 return "failed to open %s" % fn
38 def embedDashboard(self, url):
39 if url.startswith("template:"):
41 return self.readTemplate(fn)
42 elif url.startswith("http"):
43 return '<iframe src="%s" width="100%%" height="100%%" style="min-height: 1024px;" frameBorder="0"></iframe>' % url
45 def multiDashboardView(self, request, context):
46 head_template = self.head_template
47 tail_template = self.tail_template
51 <ul id="suit_form_tabs" class="nav nav-tabs nav-tabs-suit" data-tab-prefix="suit-tab">
54 dashboards = request.user.get_dashboards()
56 # customize is a special dashboard they always get
57 customize = DashboardView.objects.filter(name="Customize")
59 dashboards.append(customize[0])
61 for i,view in enumerate(dashboards):
62 body = body + '<li><a href="#dashtab-%d">%s</a></li>\n' % (i, view.name)
64 body = body + "</ul>\n"
66 for i,view in enumerate(dashboards):
68 body = body + '<div id="dashtab-%d">\n' % i
69 body = body + self.embedDashboard(url)
70 body = body + '</div>\n'
74 t = template.Template(head_template + body + self.tail_template)
77 response_kwargs.setdefault('content_type', self.content_type)
78 return self.response_class(
\r
84 def singleDashboardView(self, request, name, context):
85 head_template = self.head_template
86 tail_template = self.tail_template
88 t = template.Template(head_template + self.readTemplate(name) + self.tail_template)
91 response_kwargs.setdefault('content_type', self.content_type)
92 return self.response_class(
\r