Example #1
0
def configure(app, db=None):
    themes = Themes()
    themes.init_themes(app, app_identifier="quokka")

    try:
        from quokka.core.models import Config
        s = Config.objects.get(group='settings')
        settings = {i.name: i.value for i in s.values}
        app.config.update(settings)
    except Exception as e:
        print(str(e))
Example #2
0
    def test_setup_themes(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        assert hasattr(app, 'theme_manager')
        assert '_themes' in app.blueprints
        assert 'theme' in app.jinja_env.globals
        assert 'theme_static' in app.jinja_env.globals
Example #3
0
    def test_theme_include_static(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            data = render_template('static_parent.html').strip()
            url = static_file_url('plain', 'style.css')
            assert data == 'Application, Plain, %s' % url
Example #4
0
    def test_theme_static(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            coolurl = static_file_url('cool', 'style.css')
            cooldata = render_theme_template('cool', 'static.html').strip()
            assert cooldata == 'Cool Blue v2, %s' % coolurl
Example #5
0
    def test_template_exists(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            assert template_exists('hello.html')
            assert template_exists('_themes/cool/hello.html')
            assert not template_exists('_themes/plain/hello.html')
    def test_loader(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            src = themes_blueprint.jinja_loader.get_source(
                app.jinja_env, '_themes/cool/hello.html')
            assert src[0].strip() == 'Hello from Cool Blue v2.'
Example #7
0
    def test_render_theme_template(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            coolsrc = render_theme_template('cool', 'hello.html').strip()
            plainsrc = render_theme_template('plain', 'hello.html').strip()
            assert coolsrc == 'Hello from Cool Blue v2.'
            assert plainsrc == 'Hello from the application'
Example #8
0
    def test_static_file_url(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            url = static_file_url('cool', 'style.css')
            genurl = url_for('_themes.static', themeid='cool',
                             filename='style.css')
            assert url == genurl
Example #9
0
    def test_active_theme(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            appdata = render_template('active.html').strip()
            cooldata = render_theme_template('cool', 'active.html').strip()
            plaindata = render_theme_template('plain', 'active.html').strip()
            assert appdata == 'Application, Active theme: none'
            assert cooldata == 'Cool Blue v2, Active theme: cool'
            assert plaindata == 'Application, Active theme: plain'
Example #10
0
    def test_theme_static_outside(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            try:
                render_template('static.html')
            except RuntimeError:
                pass
            else:
                raise AssertionError("Rendering static.html should have "
                                     "caused a RuntimeError")
Example #11
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raise KeyError")
Example #12
0
def configure(app, db=None):
    themes = Themes()
    themes.init_themes(app, app_identifier="quokka")
Example #13
0
import yaml
from flask import (Flask, url_for, redirect, session, Markup, abort)
from quokka_themes import (Themes, render_theme_template, get_themes_list)
from operator import attrgetter

# default settings

DEFAULT_THEME = 'calmblue'
SECRET_KEY = 'not really secret'

# application

app = Flask(__name__)
app.config.from_object(__name__)
Themes(app, app_identifier='themesandbox')

# data


class Post(object):
    def __init__(self, data):
        self.slug = data['slug']
        self.body = data['body']
        self.title = data['title']
        self.created = data['created']

    @property
    def content(self):
        return Markup('\n\n'.join('<p>%s</p>' % line
                                  for line in self.body.splitlines()))
Example #14
0
def configure(app):
    themes = Themes()
    themes.init_themes(app, app_identifier="jing")
Example #15
0
# -*- coding: utf-8 -*-
# -*- date: 2016-02-27 19:50 -*-

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

from quokka_themes import Themes

themes = Themes()


def configure(app):
    themes.init_themes(app, app_identifier='quokka')