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 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 make_topic_menu( visuals: List[Tuple[str, Tuple[str, Visual]]]) -> List[TopicMenuTopic]: pagetypes.PagetypeTopics.load() topics = pagetypes.PagetypeTopics.get_permitted_instances() by_topic: Dict[pagetypes.PagetypeTopics, TopicMenuTopic] = {} for visual_type_name, (name, visual) in visuals: if visual["hidden"] or visual.get("mobile"): continue # Skip views not inteded to be shown in the menus topic_id = visual["topic"] try: topic = topics[topic_id] except KeyError: topic = topics["other"] url = _visual_url(visual_type_name, name) topic = by_topic.setdefault( topic, TopicMenuTopic( name=topic.name(), title=topic.title(), max_entries=topic.max_entries(), items=[], icon=topic.icon_name(), hide=topic.hide(), ), ) topic.items.append( TopicMenuItem( name=name, title=visual_title(visual_type_name, visual, visual["context"], skip_title_context=True), url=url, sort_index=visual["sort_index"], is_show_more=visual["is_show_more"], icon=visual["icon"], )) # Sort the items of all topics for topic in by_topic.values(): topic.items.sort(key=lambda i: (i.sort_index, i.title)) # Return the sorted topics return [ v for k, v in sorted(by_topic.items(), key=lambda e: (e[0].sort_index(), e[0].title())) if not v.hide ]
def default_display_title(self) -> str: # TODO: Visual and ViewSpec are both Dict[str, Any]. How are these related? return visuals.visual_title("view", self._get_view_spec(), self.context)
def display_title(self): return visuals.visual_title("view", self._get_view_spec())
def display_title(self): title = visuals.visual_title("view", self._get_view_spec()) return self._dashlet_spec.get("title", title)
def display_title(self): # TODO: Visual and ViewSpec are both Dict[str, Any]. How are these related? title = visuals.visual_title("view", self._get_view_spec()) return self._dashlet_spec.get("title", title)