Ejemplo n.º 1
0
def test_middleware_set_theme_for_site(client, site, settings):
    settings.theme = 'personal'
    settings.save()

    set_theme('wagtail')
    assert get_theme() == 'wagtail'

    client.get('/')
    assert get_theme() == 'personal'
Ejemplo n.º 2
0
    def process_request(self, request):
        try:
            site = request.site
        except AttributeError:
            raise ImproperlyConfigured(
                "ThemeMiddleware must be added after SiteMiddleware")

        if site:
            theme_settings = ThemeSettings.for_site(site)
            theme = theme_settings.theme

            if theme:
                set_theme(theme)
Ejemplo n.º 3
0
    def process_request(self, request):
        try:
            site = Site.find_for_request(request)
        except:  # noqa
            site = None

        if not site:
            raise ImproperlyConfigured("Site not found!")

        theme_settings = ThemeSettings.for_site(site)
        theme = theme_settings.theme

        if theme:
            set_theme(theme)
Ejemplo n.º 4
0
    def __call__(self, request):
        site = Site.find_for_request(request)

        if site is None:
            raise ImproperlyConfigured("Site not found!")

        theme_settings = ThemeSettings.for_site(site)
        theme = theme_settings.theme

        if theme is not None:
            set_theme(theme)

        response = self.get_response(request)
        return response
    def process_request(self, request):
        try:
            site = request.site
        except:  # noqa
            site = None

        if not site:
            raise ImproperlyConfigured(
                "ThemeMiddleware must be added after SiteMiddleware")

        theme_settings = ThemeSettings.for_site(site)
        theme = theme_settings.theme

        if theme:
            set_theme(theme)
Ejemplo n.º 6
0
def test_get_theme():
    # Check when no theme is set
    set_theme(None)
    assert not get_theme()

    # Check when theme is set
    set_theme('brand')
    assert get_theme() == 'brand'

    # Check when theme is overridden
    set_theme('personal')
    assert get_theme() == 'personal'
Ejemplo n.º 7
0
def test_get_dirs_no_theme_set():
    set_theme(None)
    template = get_template('base.html')
    assert template.render() == 'Base'
Ejemplo n.º 8
0
def test_get_dirs_with_extend():
    set_theme('brand')
    template = get_template('page.html')
    assert template.render() == 'Page - Themes Brand Base'
Ejemplo n.º 9
0
def test_get_dirs():
    set_theme('brand')
    template = get_template('base.html')
    assert template.render() == 'Themes Brand Base'