def get_test_app(): def test_loader(app): return load_themes_from(os.path.join(os.path.dirname(__file__), '../themes/')) Themes(main.app, app_identifier='yelplove', loaders=[test_loader]) return TestApp(main.app)
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
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
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.'
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
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_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'
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
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'
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")
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")
import traceback ### init Flask login_manager = LoginManager() babel = Babel() app = Flask(__name__) ### next steps... #app.debug = True login_manager.init_app(app) babel.init_app(app) Themes(app, app_identifier='domogik-admin') app.jinja_env.globals['bootstrap_is_hidden_field'] =\ is_hidden_field_filter app.jinja_env.add_extension('jinja2.ext.do') # in a real app, these should be configured through Flask-Appconfig app.config['SECRET_KEY'] = 'devkey' app.config['RECAPTCHA_PUBLIC_KEY'] = \ '6Lfol9cSAAAAADAkodaYl9wvQCwBMr3qGR_PPHcw' app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Paris' # jinja 2 filters def format_babel_datetime(value, format='medium'):
# -*- coding: utf-8 -*- # flake8: noqa from flask import Flask from flask.ext.themes2 import Themes import config from util.auth import is_admin from util.converter import RegexConverter from util.csrf import generate_csrf_token app = Flask(__name__.split('.')[0]) app.secret_key = config.SECRET_KEY app.url_map.converters['regex'] = RegexConverter app.jinja_env.globals['config'] = config app.jinja_env.globals['csrf_token'] = generate_csrf_token app.jinja_env.globals['is_admin'] = is_admin Themes(app, app_identifier='yelplove') import views
# -*- coding: utf-8 -*- """ Awesome New Site ================== This will be the new website init """ from flask import Flask from flask.ext.themes2 import Themes from .blueprint import blueprint from .config import Config app = Flask('awesome_new_site') # this try block allows local development settings to be set try: app.config.from_pyfile('proteus/awesome_new_site.cfg') except (RuntimeError, IOError): # local settings are not found, we can pass pass # Register blueprint and theme app.register_blueprint(blueprint) Themes(app, app_identifier='proteus')
# -*- coding: utf-8 -*- from pymongo import MongoClient from flask import current_app from flask.ext.themes2 import Themes class UltrADB(object): def __init__(self, app=None): self.app = app if app: self.init_app(app) def init_app(self, app): # 连接数据库 client = MongoClient( host=app.config['DB_HOST'], port=app.config['DB_PORT'], tz_aware=True, ) db = client[app.config['DB_NAME']] self.topics = db[app.config['TOPIC_COLLECTION']] self.photos = db[app.config['PHOTO_COLLECTION']] self.blurs = db[app.config['BLUR_COLLECTION']] self.similarities = db['raw_similarities'] self.sites = db['raw_sites'] db = UltrADB() themes = Themes()
def configure_extensions(app): db.init_app(app) mail.init_app(app) Themes(app, app_identifier='monitor')
import os import uuid import configargparse from cert_tools import helpers from cert_tools import jsonpath_helpers from cert_schema import * from cert_schema.model import scope_name from flask import (Flask) from flask.ext.themes2 import (Themes) app = Flask(__name__) Themes(app, app_identifier='cert_tools') OPEN_BADGES_V2_CONTEXT = OPEN_BADGES_V2_CANONICAL_CONTEXT BLOCKCERTS_V2_CONTEXT = BLOCKCERTS_V2_CANONICAL_CONTEXT def create_badge_section(config): cert_image_path = os.path.join(config.abs_data_dir, config.cert_image_file) issuer_image_path = os.path.join(config.abs_data_dir, config.issuer_logo_file) with open('data.json') as data_file: award_obj = json.load(data_file) badge = { 'type': 'BadgeClass', 'id': helpers.URN_UUID_PREFIX + config.badge_id,
def configure_extensions(app): configure_i18n(app) db.init_app(app) mail.init_app(app) Themes(app, app_identifier=__name__) FlaskUtilJs(app)
from flask.ext.themes2 import Themes # from flask.ext.mail import Mail import os # Yay! I love coding Python X :( try: unicode = unicode except NameError: # unicode is undefined: We are running Python 3 unicode = str basestring = (str, bytes) else: # unicode is defined: We are running Python 2 bytes = str app = Flask(__name__) app.config.from_pyfile('config.py') app.secret_key = os.urandom(24) Themes(app) # mail = Mail(app) # email_env = Environment(loader=PackageLoader('impression', 'templates/emails')) db = SQLAlchemy(app) # mail = Mail(app) if not os.environ.get('RUNNING_ALEMBIC'): import views
import logging.config import os import gridfs from flask import (Flask) from flask.ext.themes2 import (Themes) from pymongo import MongoClient from simplekv.fs import FilesystemStore BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) app = Flask(__name__) Themes(app, app_identifier='cert_viewer') logging.config.fileConfig(os.path.join(BASE_DIR, 'logging.conf')) log = logging.getLogger(__name__) mongo_connection = None cert_store = None verifier = None intro_store = None from cert_store.certificate_store import CertificateStore, V1AwareCertificateStore from cert_store.gridfs_key_value_store import GridfsKeyValueStore from cert_viewer.verifier_bridge import V1AwareCertificateVerifierBridge, CertificateVerifierBridge from cert_viewer.introduction_store_bridge import IntroStore def configure_app(configuration): # Configure data sources mongo_client = MongoClient(host=configuration.mongodb_uri)
import yaml from flask import (Flask, url_for, redirect, session, Markup, abort) #from flask.ext.themes2 import (setup_themes, render_theme_template, get_themes_list) from flask.ext.themes2 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()))