示例#1
0
def test_theme_request_context_integration(my_theme, request_context):
    theme.from_config("facelift")

    theme.set("")
    assert theme.get() == "facelift"

    theme.set("not_existing")
    assert theme.get() == "facelift"

    theme.set("my_theme")
    assert theme.get() == "my_theme"
示例#2
0
    def update(self):
        import cmk.gui.sidebar as sidebar  # pylint: disable=import-outside-toplevel

        dashlet = self._dashlet_spec
        snapin = sidebar.snapin_registry.get(self._dashlet_spec["snapin"])
        if not snapin:
            raise MKUserError(None,
                              _("The configured element does not exist."))
        snapin_instance = snapin()

        html.browser_reload = self.refresh_interval()
        html.html_head(_("Sidebar element"))
        html.open_body(class_="side", data_theme=theme.get())
        html.open_div(id_="check_mk_sidebar")
        html.open_div(id_="side_content")
        html.open_div(id_="snapin_container_%s" % dashlet["snapin"],
                      class_="snapin")
        html.open_div(id_="snapin_%s" % dashlet["snapin"], class_="content")
        styles = snapin_instance.styles()
        if styles:
            html.style(styles)
        snapin_instance.show()
        html.close_div()
        html.close_div()
        html.close_div()
        html.close_div()
        html.body_end()
示例#3
0
    def _show_body_start(self) -> None:
        body_classes = ["side"] + (["screenshotmode"]
                                   if active_config.screenshotmode else [])

        if not user.may("general.see_sidebar"):
            html.open_body(class_=body_classes, data_theme=theme.get())
            return

        interval = (active_config.sidebar_notify_interval
                    if active_config.sidebar_notify_interval is not None else
                    "null")
        html.open_body(
            class_=body_classes,
            onload=
            "cmk.sidebar.initialize_scroll_position(); cmk.sidebar.init_messages_and_werks(%s, %s); "
            % (json.dumps(interval), json.dumps(bool(may_acknowledge()))),
            data_theme=theme.get(),
        )
示例#4
0
def add_default_render_options(
    graph_render_options: GraphRenderOptions, render_unthemed: bool = False
) -> GraphRenderOptions:
    options = get_default_graph_render_options()
    options.update(graph_render_options)
    options.setdefault("size", user.load_file("graph_size", (70, 16)))

    # Users can't modify graph colors. Only defaults are allowed
    theme_colors = _graph_colors(theme.get() if not render_unthemed else "pdf")
    options.update(theme_colors)

    return options
示例#5
0
    def page(self) -> AjaxPageResult:
        check_csrf_token()
        themes = [theme for theme, _title in theme_choices()]
        current_theme = theme.get()
        try:
            theme_index = themes.index(current_theme)
        except ValueError:
            raise MKUserError(None, _("Could not determine current theme."))

        if len(themes) == theme_index + 1:
            new_theme = themes[0]
        else:
            new_theme = themes[theme_index + 1]

        _set_user_attribute("ui_theme", new_theme)
        return {}
示例#6
0
def _get_current_theme_titel() -> str:
    return [
        titel for theme_id, titel in theme.theme_choices
        if theme_id == theme.get()
    ][0]
示例#7
0
 def body_start(
     self, title: str = "", javascripts: Optional[Sequence[str]] = None, force: bool = False
 ) -> None:
     self.html_head(title, javascripts, force)
     self.open_body(class_=self._get_body_css_classes(), data_theme=theme.get())
示例#8
0
def get_themed_perfometer_bg_color() -> str:
    """Return the theme specific background color for perfometer rendering"""
    if theme.get() == "modern-dark":
        return "#bdbdbd"
    # else (classic and modern theme)
    return "#ffffff"