Skip to content

Commit

Permalink
Load tab context data during init for "preload" tabs. Fixes bug 959800.
Browse files Browse the repository at this point in the history
Change-Id: If05c022def2e97bbae682db65d4311b1401e850d
  • Loading branch information
gabrielhurley committed Mar 19, 2012
1 parent 9931748 commit 8b1d028
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -211,9 +211,10 @@ def test_instance_log(self):

url = reverse('horizon:nova:instances_and_volumes:instances:console',
args=[server.id])
tg = InstanceDetailTabs(self.request)
tg = InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("log").get_id())
res = self.client.get(url + qs)
self.assertNoMessages()
self.assertIsInstance(res, http.HttpResponse)
self.assertContains(res, CONSOLE_OUTPUT)

Expand All @@ -228,7 +229,7 @@ def test_instance_log_exception(self):

url = reverse('horizon:nova:instances_and_volumes:instances:console',
args=[server.id])
tg = InstanceDetailTabs(self.request)
tg = InstanceDetailTabs(self.request, instance=server)
qs = "?%s=%s" % (tg.param_name, tg.get_tab("log").get_id())
res = self.client.get(url + qs)
self.assertContains(res, "Unable to get log for")
Expand Down
12 changes: 11 additions & 1 deletion horizon/tabs/base.py
Expand Up @@ -95,6 +95,10 @@ def __init__(self, request, **kwargs):
self._tabs = SortedDict(tab_instances)
if not self._set_active_tab():
self.tabs_not_available()
# Preload all data that will be loaded to allow errors to be displayed
for tab in self._tabs.values():
if tab.load:
tab._context_data = tab.get_context_data(request)

def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.slug)
Expand Down Expand Up @@ -249,6 +253,12 @@ def load(self):
load_preloaded = self.preload or self.is_active()
return load_preloaded and self._allowed and self._enabled

@property
def context_data(self):
if not getattr(self, "_context_data", None):
self._context_data = self.get_context_data(self.request)
return self._context_data

def render(self):
"""
Renders the tab to HTML using the :meth:`~horizon.tabs.Tab.get_data`
Expand All @@ -263,7 +273,7 @@ def render(self):
if not self.load:
return ''
try:
context = self.get_context_data(self.request)
context = self.context_data
except exceptions.Http302:
raise
except:
Expand Down

0 comments on commit 8b1d028

Please sign in to comment.