Esempio n. 1
0
    def __call__(self, environ, start_response):
        req = http.Request(environ)

        output_format = get_output_format(
            req.get_ascii_input_mandatory("output_format", "html").lower())
        mime_type = get_mime_type_from_output_format(output_format)

        resp = Response(headers=default_response_headers(req),
                        mimetype=mime_type)
        funnel = OutputFunnel(resp)

        timeout_manager = TimeoutManager()
        timeout_manager.enable_timeout(req.request_timeout)

        theme = Theme()

        with AppContext(self), RequestContext(
                req=req,
                resp=resp,
                funnel=funnel,
                html_obj=htmllib.html(req, resp, funnel, output_format),
                timeout_manager=timeout_manager,
                display_options=DisplayOptions(),
                theme=theme,
        ), patch_json(json):
            config.initialize()
            theme.from_config(config.ui_theme, config.theme_choices())
            return self.wsgi_app(environ, start_response)
Esempio n. 2
0
def test_theme_broken_meta(my_theme):
    (my_theme / "theme.json").open(mode="w", encoding="utf-8").write(
        six.text_type("{\"titlewrong\": xyz\"bla\"}"))

    assert config.theme_choices() == sorted([
        ("my_theme", u"my_theme"),
    ])
def test_ui_theme_registration():
    var = config_variable_registry["ui_theme"]()
    assert var.domain() == ConfigDomainGUI
    assert var.group() == ConfigVariableGroupUserInterface

    valuespec = var.valuespec()
    assert isinstance(valuespec, DropdownChoice)
    assert valuespec.choices() == config.theme_choices()
Esempio n. 4
0
def test_theme_choices_override(theme_dirs, my_theme):
    local_theme_path = theme_dirs[1]

    my_dir = local_theme_path / "my_theme"
    my_dir.mkdir()
    (my_dir / "theme.json").open(mode="w", encoding="utf-8").write(
        six.text_type(json.dumps({"title": "Fixed theme"})))

    assert config.theme_choices() == sorted([
        ("my_theme", u"Fixed theme"),
    ])
Esempio n. 5
0
def test_theme_request_context_integration(my_theme, register_builtin_html):
    theme.from_config("facelift", config.theme_choices())

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

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

    theme.set("my_theme")
    assert theme.get() == "my_theme"
Esempio n. 6
0
def test_theme_choices_local_theme(theme_dirs, my_theme):
    local_theme_path = theme_dirs[1]

    my_dir = local_theme_path / "my_improved_theme"
    my_dir.mkdir()
    (my_dir / "theme.json").open(mode="w", encoding="utf-8").write(
        six.text_type(json.dumps({"title": "Määh Bettr Theme :-D"})))

    assert config.theme_choices() == sorted([
        ("my_theme", u"Määh Theme :-)"),
        ("my_improved_theme", u"Määh Bettr Theme :-D"),
    ])
Esempio n. 7
0
 def valuespec(self):
     return Alternative(
         title=_("User interface theme"),
         orientation="horizontal",
         elements=[
             FixedValue(
                 None,
                 title=_("Use the default theme"),
                 totext="",
             ),
             DropdownChoice(
                 title=_("Set custom theme"),
                 choices=theme_choices(),
             ),
         ],
     )
Esempio n. 8
0
 def _SearchContext(self) -> Iterator[None]:
     _request = Request(create_environ())
     _response = Response()
     _funnel = OutputFunnel(_response)
     _theme = Theme()
     _theme.from_config(config.ui_theme, config.theme_choices())
     with RequestContext(
             req=_request,
             resp=_response,
             funnel=_funnel,
             html_obj=html(_request,
                           _response,
                           _funnel,
                           output_format="html"),
             display_options=DisplayOptions(),
             theme=_theme,
     ), UserContext(self._user_id):
         yield
Esempio n. 9
0
def test_theme_choices_normal(my_theme):
    assert config.theme_choices() == [("my_theme", u"Määh Theme :-)")]
Esempio n. 10
0
def test_theme_choices_empty(theme_dirs):
    assert config.theme_choices() == []
Esempio n. 11
0
def _get_current_theme_titel() -> str:
    return [
        titel for theme_id, titel in config.theme_choices()
        if theme_id == html.get_theme()
    ][0]
Esempio n. 12
0
def fixture_th() -> Theme:
    th = Theme()
    th.from_config("modern-dark", config.theme_choices())
    assert th.get() == "modern-dark"
    return th