def copy_view_into_dashlet( dashlet: DashletConfig, nr: DashletId, view_name: str, add_context: Optional[VisualContext] = None, load_from_all_views: bool = False, ) -> None: permitted_views = get_permitted_views() # it is random which user is first accessing # an apache python process, initializing the dashboard loading and conversion of # old dashboards. In case of the conversion we really try hard to make the conversion # work in all cases. So we need all views instead of the views of the user. if load_from_all_views and view_name not in permitted_views: # This is not really 100% correct according to the logic of visuals.available(), # but we do this for the rare edge case during legacy dashboard conversion, so # this should be sufficient view = None for (_unused, n), this_view in get_all_views().items(): # take the first view with a matching name if view_name == n: view = this_view break if not view: raise MKGeneralException( _("Failed to convert a builtin dashboard which is referencing " 'the view "%s". You will have to migrate it to the new ' "dashboard format on your own to work properly.") % view_name) else: view = permitted_views[view_name] view = copy.deepcopy(view) # Clone the view dashlet.update(view) if add_context: dashlet["context"].update(add_context) # Overwrite the views default title with the context specific title dashlet["title"] = visuals.visual_title("view", view, dashlet["context"]) # TODO: Shouldn't we use the self._dashlet_context_vars() here? name_part: HTTPVariables = [("view_name", view_name)] singlecontext_vars = cast( HTTPVariables, list( visuals.get_singlecontext_vars( view["context"], view["single_infos"], ).items()), ) dashlet["title_url"] = makeuri_contextless( request, name_part + singlecontext_vars, filename="view.py", ) dashlet["type"] = "view" dashlet["name"] = "dashlet_%d" % nr dashlet["show_title"] = True dashlet["mustsearch"] = False
def get_topology_view_and_filters() -> Tuple[View, List[Filter]]: view_name = "topology_filters" view_spec = get_permitted_views()[view_name] view = View(view_name, view_spec, view_spec.get("context", {})) filters = cmk.gui.visuals.filters_of_visual(view.spec, view.datasource.infos, link_filters=view.datasource.link_filters) show_filters = cmk.gui.visuals.visible_filters_of_visual(view.spec, filters) return view, show_filters
def copy_view_into_dashlet(dashlet, nr, view_name, add_context=None, load_from_all_views=False): # type: (DashletConfig, DashletId, str, VisualContext, bool) -> None permitted_views = get_permitted_views() # it is random which user is first accessing # an apache python process, initializing the dashboard loading and conversion of # old dashboards. In case of the conversion we really try hard to make the conversion # work in all cases. So we need all views instead of the views of the user. if load_from_all_views and view_name not in permitted_views: # This is not really 100% correct according to the logic of visuals.available(), # but we do this for the rare edge case during legacy dashboard conversion, so # this should be sufficient view = None for (_u, n), this_view in get_all_views().items(): # take the first view with a matching name if view_name == n: view = this_view break if not view: raise MKGeneralException( _("Failed to convert a builtin dashboard which is referencing " "the view \"%s\". You will have to migrate it to the new " "dashboard format on your own to work properly.") % view_name) else: view = permitted_views[view_name] view = copy.deepcopy(view) # Clone the view dashlet.update(view) if add_context: dashlet['context'].update(add_context) # Overwrite the views default title with the context specific title dashlet['title'] = visuals.visual_title('view', view) # TODO: Shouldn't we use the self._dashlet_context_vars() here? name_part = [('view_name', view_name)] # type: HTTPVariables singlecontext_vars = cast( HTTPVariables, visuals.get_singlecontext_vars( view["context"], view["single_infos"], ).items()) dashlet['title_url'] = html.makeuri_contextless(name_part + singlecontext_vars, filename='view.py') dashlet['type'] = 'view' dashlet['name'] = 'dashlet_%d' % nr dashlet['show_title'] = True dashlet['mustsearch'] = False
def _get_topology_view_and_filters(self): view_spec = get_permitted_views()["topology_filters"] view_name = "topology_filters" view = View(view_name, view_spec) filters = cmk.gui.visuals.filters_of_visual( view.spec, view.datasource.infos, link_filters=view.datasource.link_filters) show_filters = cmk.gui.visuals.visible_filters_of_visual( view.spec, filters) return view, show_filters