Gabriel Hurley b8754d5ecd Updates Image Details page to match other details pages. Fixes bug 955625.
While updating these, a bug was discovered in the tab exception handling
which is also fixed by this patch. Fixes bug 955642.

Also incorporates some cleanup on the other details pages so that
they are all uniform and at their best.

Additionally, added a command to run_tests.sh to update all the translation
strings (./run_tests.sh -m or --makemessages).

Updates translation files.

Change-Id: I61287b91fb442f7343c2ddebfcc547dc559efbdf
2012-03-15 11:40:46 -07:00

53 lines
1.8 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_class 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)
def render_to_response(self, *args, **kwargs):
response = super(TabView, self).render_to_response(*args, **kwargs)
# Because Django's TemplateView uses the TemplateResponse class
# to provide deferred rendering (which is usually helpful), if
# a tab group raises an Http302 redirect (from exceptions.handle for
# example) the exception is actually raised *after* the final pass
# of the exception-handling middleware.
response.render()
return response