Refreshing tab content in openstack django webapp

asked 2014-06-04 04:28:04 -0600

avnivamsi gravatar image

updated 2014-06-04 04:37:04 -0600

I am facing a weird issue in Openstack webapp where i am trying to refresh the tabbed content, however i end up appending the refreshed tab content to the the HTML DOM.

The flow of the code is simple except that i donot understand how the HTML is being attached to DOM instead of the existing tab.

The code flow is:

foo.get --->TabView.get --> TabView.handle_tabbed_response.

I desire that the tab be updated and not that the refresh tab content appended to the existing tab,

What have i done:

 Class foo((tabs.TabView):
        tab_group_class = (barTabs)
        template_name = 'project/xyz/index.html'

        def get(self, request, *args, **kwargs):
            ######## Business Logic
            thelper = business_logic(request)
            return super(foo, self).get(request, *args, **kwargs)

        def get_initial(self):
            initial = super(foo, self).get_initial()
            return initial

    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

        .. 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
        _tab_group = 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, **kwargs):
            """ Returns the initialized tab group for this view. """
            if self._tab_group is None:
                self._tab_group = self.tab_group_class(request, **kwargs)
            return self._tab_group

        def get_context_data(self, **kwargs):
            """ Adds the ``tab_group`` variable to the context data. """
            context = super(TabView, self).get_context_data(**kwargs)
                tab_group = self.get_tabs(self.request, **kwargs)
                context["tab_group"] = tab_group
                # Make sure our data is pre-loaded to capture errors.
            except Exception:
            return context

        def handle_tabbed_response(self, tab_group, context):
            Sends back an AJAX-appropriate response for the tab group if
            required, otherwise renders the response as normal.
            if self.request.is_ajax():
                if tab_group.selected:
                    return http.HttpResponse(tab_group.selected.render())
                    return http.HttpResponse(tab_group.render())
            return self.render_to_response(context)

        def get(self, request, *args, **kwargs):
            context = self.get_context_data(**kwargs)
            return self.handle_tabbed_response(context["tab_group"], 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.
            return response

Please help.

edit retag flag offensive close merge delete