def guess_view(self, paramdict): rl = [] getvlist = [x for x in views.all_views() if x[1].getParams] for v, vi in getvlist: for param in vi.getParams: if param in paramdict: rl.append(v) break if len(rl) == 1: return rl[0] else: return None
def load_view_into_dashlet(dashlet, nr, view_name, add_context=None, load_from_all_views=False): import views views.load_views() permitted_views = views.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 views.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["title_url"] = html.makeuri_contextless( [("view_name", view_name)] + visuals.get_singlecontext_vars(view).items(), filename="view.py" ) dashlet["type"] = "view" dashlet["name"] = "dashlet_%d" % nr dashlet["show_title"] = True