tuskar-ui/horizon/tabs/views.py
Gabriel Hurley 052aa55d34 Unifies the project packaging into one set of modules.
There are no longer two separate projects living inside the horizon
repository. There is a single project now with a single setup.py,
single README, etc.

The openstack-dashboard/dashboard django project is now named
"openstack_dashboard" and lives as an example project in the
topmost horizon directory.

The "horizon/horizon" directory has been bumped up a level and now
is directly on the path when the root horizon directory is on
your python path.

Javascript media which the horizon module directly relies upon
now ships in the horizon/static dir rather than
openstack-dashboard/dashboard/static.

All the corresponding setup, installation, build, and env scripts
have been updated accordingly.

Implements blueprint unified-packaging.

Change-Id: Ieed8e3c777432cd046c3e0298869a9428756ab62
2012-02-29 00:20:13 -08:00

43 lines
1.3 KiB
Python

from django import http
from django.views import generic
from horizon import exceptions
class TabView(generic.TemplateView):
"""
A generic class-based view for displaying a :class:`horizon.tabs.TabGroup`.
This view handles selecting specific tabs and deals with AJAX requests
gracefully.
.. attribute:: tab_group_class
The only required attribute for ``TabView``. It should be a class which
inherits from :class:`horizon.tabs.TabGroup`.
"""
tab_group_class = None
def __init__(self):
if not self.tab_group_class:
raise AttributeError("You must set the tab_group attribute on %s."
% self.__class__.__name__)
def get_tabs(self, request, *args, **kwargs):
return self.tab_group_class(request, **kwargs)
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
try:
tab_group = self.get_tabs(request, *args, **kwargs)
context["tab_group"] = tab_group
except:
exceptions.handle(request)
if request.is_ajax():
if tab_group.selected:
return http.HttpResponse(tab_group.selected.render())
else:
return http.HttpResponse(tab_group.render())
return self.render_to_response(context)