How to use the horizon.tabs function in horizon

To help you get started, we’ve selected a few horizon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / tabs.py View on Github external
if filter_field is None and filter_field_session is not None:
            filter_field = filter_field_session
        setattr(table.base_actions["filter"], "filter_string", filter_string)
        setattr(table.base_actions["filter"], "filter_field", filter_field)
        filter_info = {
            'action': filter_action,
            'value_param': param_name,
            'value': filter_string,
            'field_param': filter_field_param,
            'field': filter_field,
            'changed': changed
        }
        return filter_info


class PaginationFriendlyTabGroup(tabs.TabGroup):
    def load_tab_data(self):
        """Preload all data that for the tabs that will be displayed."""
        request_without_marker = u.delete_pagination_params_from_request(
            self.request, save_limit=True)
        for tab in self._tabs.values():
            current_tab_id = tab.slug

            tab_request = self.request.GET.get('tab')
            request_tab_id = None

            if tab_request:
                request_tab_id = tab_request.split(base.SEPARATOR)[1]
            if request_tab_id and current_tab_id != request_tab_id:
                try:
                    tab.request = request_without_marker
                    tab._data = tab.get_context_data(request_without_marker)
github openstack / sahara-dashboard / saharadashboard / plugins / tabs.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from django.utils.translation import ugettext_lazy as _
from horizon import tabs

from saharadashboard.api.client import client as saharaclient

LOG = logging.getLogger(__name__)


class DetailsTab(tabs.Tab):
    name = _("Details")
    slug = "plugin_details_tab"
    template_name = ("plugins/_details.html")

    def get_context_data(self, request):
        plugin_id = self.tab_group.kwargs['plugin_id']
        sahara = saharaclient(request)
        plugin = sahara.plugins.get(plugin_id)
        return {"plugin": plugin}


class PluginDetailsTabs(tabs.TabGroup):
    slug = "cluster_details"
    tabs = (DetailsTab,)
    sticky = True
github openstack / tacker-horizon / tacker_horizon / openstack_dashboard / dashboards / nfv / vnfcatalog / tabs.py View on Github external
return catalogs
        except Exception:
            self._has_more = False
            error_message = _('Unable to get vnf catalogs')
            exceptions.handle(self.request, error_message)

            return []


class VNFCatalogTabs(tabs.TabGroup):
    slug = "vnfcatalog_tabs"
    tabs = (VNFCatalogTab,)
    sticky = True


class TemplateTab(tabs.Tab):
    name = _("Template")
    slug = "template"
    template_name = ("nfv/vnfcatalog/template.html")

    def get_context_data(self, request):
        return {'vnfd': self.tab_group.kwargs['vnfd']}


class VNFDEventsTab(tabs.TableTab):
    name = _("Events Tab")
    slug = "events_tab"
    table_classes = (utils.EventsTable,)
    template_name = ("horizon/common/_detail_table.html")
    preload = False

    def has_more_data(self, table):
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / clusters / cluster_templates / tabs.py View on Github external
try:
            table = self._tables['cluster_templates']
            search_opts = {}
            filter = self.get_server_filter_info(table.request, table)
            if filter['value'] and filter['field']:
                search_opts = {filter['field']: filter['value']}
            cluster_templates = saharaclient.cluster_template_list(
                self.request, search_opts)
        except Exception:
            cluster_templates = []
            exceptions.handle(self.request,
                              _("Unable to fetch cluster template list"))
        return cluster_templates


class GeneralTab(tabs.Tab):
    name = _("General Info")
    slug = "cluster_template_details_tab"
    template_name = "cluster_templates/_details.html"

    def get_context_data(self, request):
        template_id = self.tab_group.kwargs['template_id']
        try:
            template = saharaclient.cluster_template_get(request, template_id)
        except Exception as e:
            template = {}
            LOG.error("Unable to fetch cluster template details: %s" % str(e))
        if saharaclient.VERSIONS.active == '2':
            template.hadoop_version = template.plugin_version
        return {"template": template}
github openstack / horizon / openstack_dashboard / dashboards / identity / users / views.py View on Github external
_("Unable to retrieve user roles."),
                              redirect=redirect)
        roles.sort(key=operator.attrgetter("id"))
        kwargs['roles'] = roles
        return kwargs

    def get_initial(self):
        # Set the domain of the user
        domain = api.keystone.get_default_domain(self.request)
        default_role = api.keystone.get_default_role(self.request)
        return {'domain_id': domain.id,
                'domain_name': domain.name,
                'role_id': getattr(default_role, "id", None)}


class DetailView(tabs.TabView):
    tab_group_class = user_tabs.UserDetailTabs
    template_name = 'horizon/common/_detail.html'
    page_title = "{{ user.name }}"

    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        user = self.get_data()
        table = project_tables.UsersTable(self.request)
        context["user"] = user
        context["url"] = self.get_redirect_url()
        context["actions"] = table.render_row_actions(user)
        options = getattr(user, "options", {})
        context["lock_password"] = options.get("lock_password", False)
        return context

    @memoized.memoized_method
github openstack / manila-ui / manila_ui / dashboards / project / security_services / views.py View on Github external
return self._object

    def get_context_data(self, **kwargs):
        context = super(AddSecurityServiceView,
                        self).get_context_data(**kwargs)
        context['share_network'] = self.get_object()
        return context

    def get_initial(self):
        share_net = self.get_object()
        return {'share_net_id': self.kwargs["share_network_id"],
                'name': share_net.name,
                'description': share_net.description}


class Detail(tabs.TabView):
    tab_group_class = ss_tabs.SecurityServiceDetailTabs
    template_name = 'project/security_services/detail.html'
    redirect_url = reverse_lazy('horizon:project:security_services:index')

    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        sec_service = self.get_data()
        context["sec_service"] = sec_service
        sec_service_display_name = sec_service.name or sec_service.id
        context["sec_service_display_name"] = sec_service_display_name
        context["page_title"] = _("Security Service Details: "
                                  "%(service_display_name)s") % \
            {'service_display_name': sec_service_display_name}
        return context

    @memoized.memoized_method
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / clusters / cluster_templates / views.py View on Github external
from sahara_dashboard.api import sahara as saharaclient
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.tables as ct_tables
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.tabs as _tabs
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.workflows.copy as copy_flow
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.workflows.create as create_flow
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.workflows.edit as edit_flow
import sahara_dashboard.content.data_processing.clusters. \
    cluster_templates.forms.import_forms as import_forms


class ClusterTemplateDetailsView(tabs.TabView):
    tab_group_class = _tabs.ClusterTemplateDetailsTabs
    template_name = 'horizon/common/_detail.html'
    page_title = "{{ template.name|default:template.id }}"

    @memoized.memoized_method
    def get_object(self):
        ct_id = self.kwargs["template_id"]
        try:
            return saharaclient.cluster_template_get(self.request, ct_id)
        except Exception:
            msg = _('Unable to retrieve details for '
                    'cluster template "%s".') % ct_id
            redirect = self.get_redirect_url()
            exceptions.handle(self.request, msg, redirect=redirect)

    def get_context_data(self, **kwargs):
github openstack / horizon / openstack_dashboard / dashboards / project / vg_snapshots / views.py View on Github external
vg_snapshots = []
            exceptions.handle(self.request, _("Unable to retrieve "
                                              "volume group snapshots."))
        try:
            groups = dict((g.id, g) for g
                          in api.cinder.group_list(self.request))
        except Exception:
            groups = {}
            exceptions.handle(self.request,
                              _("Unable to retrieve volume groups."))
        for gs in vg_snapshots:
            gs.group = groups.get(gs.group_id)
        return vg_snapshots


class DetailView(tabs.TabView):
    tab_group_class = vg_snapshot_tabs.DetailTabs
    template_name = 'horizon/common/_detail.html'
    page_title = "{{ vg_snapshot.name|default:vg_snapshot.id }}"

    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        vg_snapshot = self.get_data()
        table = vg_snapshot_tables.GroupSnapshotsTable(self.request)
        context["vg_snapshot"] = vg_snapshot
        context["url"] = self.get_redirect_url()
        context["actions"] = table.render_row_actions(vg_snapshot)
        return context

    @memoized.memoized_method
    def get_data(self):
        try:
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / clusters / clusters / views.py View on Github external
from sahara_dashboard.api import sahara as saharaclient
import sahara_dashboard.content.data_processing.clusters.clusters. \
    tables as c_tables
import sahara_dashboard.content.data_processing.clusters.clusters. \
    tabs as _tabs
import sahara_dashboard.content.data_processing.clusters.clusters. \
    workflows.create as create_flow
import sahara_dashboard.content.data_processing.clusters.clusters. \
    workflows.scale as scale_flow
import sahara_dashboard.content.data_processing.clusters.clusters. \
    workflows.update as update_flow
import sahara_dashboard.content.data_processing.utils.helpers as helpers


class ClusterDetailsView(tabs.TabView):
    tab_group_class = _tabs.ClusterDetailsTabs
    template_name = 'horizon/common/_detail.html'
    page_title = "{{ cluster.name|default:cluster.id }}"

    @memoized.memoized_method
    def get_object(self):
        cl_id = self.kwargs["cluster_id"]
        try:
            return saharaclient.cluster_get(self.request, cl_id)
        except Exception:
            msg = _('Unable to retrieve details for cluster "%s".') % cl_id
            redirect = self.get_redirect_url()
            exceptions.handle(self.request, msg, redirect=redirect)

    def get_context_data(self, **kwargs):
        context = super(ClusterDetailsView, self).get_context_data(**kwargs)
github openstack / sahara-dashboard / saharadashboard / plugins / views.py View on Github external
from saharadashboard.plugins.tables import PluginsTable
from saharadashboard.plugins.tabs import PluginDetailsTabs

LOG = logging.getLogger(__name__)


class PluginsView(tables.DataTableView):
    table_class = PluginsTable
    template_name = 'plugins/plugins.html'

    def get_data(self):
        sahara = saharaclient(self.request)
        return sahara.plugins.list()


class PluginDetailsView(tabs.TabView):
    tab_group_class = PluginDetailsTabs
    template_name = 'plugins/details.html'

    def get_context_data(self, **kwargs):
        context = super(PluginDetailsView, self).get_context_data(**kwargs)
        return context

    def get_data(self):
        pass