Esempio n. 1
0
def create_app(name=None):
    app = Flask(name)

    if os.environ.get('PRODUCTION'):
        app.config.from_object(ProductionConfig)
        print "running with ProductionConfig"
    else:
        app.config.from_object(DefaultConfig)
        print "running with DefaultConfig"

    # sentry
    if app.config.get('SENTRY_DSN'):
        sentry = Sentry()
        sentry.init_app(app)
        app.sentry = sentry

    # assets
    assets = Environment(app)
    assets.url = app.static_url_path
    scss_bundle = Bundle('css/*.scss', 'css/*.css',
        filters=['scss', 'cssmin'], depends='css/*.scss', output='css/all.css')
    assets.register('scss_all', scss_bundle)
    js_bundle = Bundle('js/*.js', filters='rjsmin', output='js/all.js')
    assets.register('js_all', js_bundle)
    Compress(app)

    # cache
    if app.config['DEBUG']:
        cache_type = 'null'
    else:
        cache_type = 'simple'

    cache = Cache(config={'CACHE_TYPE': cache_type})
    cache.init_app(app)
    app.cache = cache

    # CDN
    cdn = CDN()
    cdn.init_app(app)

    # workaround flask-assets / flask-cdn integration
    if app.config.get('CDN_HTTPS'):
        cdn_scheme = 'https'
    else:
        cdn_scheme = 'http'
    if app.config.get('FLASK_ASSETS_USE_CDN') and app.config.get('CDN_DOMAIN'):
        app.jinja_env.globals['FLASK_CDN'] = '%s://%s' % (cdn_scheme, app.config['CDN_DOMAIN'])

    return app
Esempio n. 2
0
def configure_cdn_url_for(app):
    u"""是的url_for智能使用cdn地址"""
    cdn = CDN()
    cdn.init_app(app)
Esempio n. 3
0
import stripe
import structlog

from flask import Flask, g, request, redirect
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager, current_user
from flask.ext.cdn import CDN
from flask_redis import Redis
from flask_limiter import Limiter
from flask_limiter.util import get_ipaddr
import settings

DB = SQLAlchemy()
redis_store = Redis()
stripe.api_key = settings.STRIPE_SECRET_KEY
cdn = CDN()

import routes
from users.models import User


def configure_login(app):
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'register'

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))

    @app.before_request
Esempio n. 4
0
    def setUp(self):
        self.app = Flask(__name__)
        self.app.testing = True

        CDN(self.app)
Esempio n. 5
0
	    config = os.path.join(os.environ['VILFREDO_SETTINGS'], 'settings.cfg')
	    if os.path.isfile(config):
	        app.config.from_pyfile(config, silent=True)
    #app.config.from_envvar('VILFREDO_SETTINGS', silent=True)
    #config = os.path.join(app.root_path, 'settings.cfg')
    #app.config.from_pyfile(config, silent=True)

app = Flask(__name__, static_url_path='')
config_app(app)

import VilfredoReloadedCore.views
import VilfredoReloadedCore.api.v2.api

mail = Mail(app)

CDN(app)

from flask_util_js import FlaskUtilJs
fujs = FlaskUtilJs(app)

# Passing mode='w' to file handler not causing overwrite
if os.path.isfile(app.config['LOG_FILE_PATH']):
    try:
        os.remove(app.config['LOG_FILE_PATH'])
    except IOError:
        print 'Failed to delete log file ' + app.config['LOG_FILE_PATH']

# Logging
import logging
import logging.config
basedir = os.path.abspath(os.path.dirname(__file__))
Esempio n. 6
0
 def client_get(self, ufs):
     CDN(self.app)
     client = self.app.test_client()
     return client.get('/%s' % ufs)
Esempio n. 7
0
from daimaduan.utils.filters import datetimeformat
from daimaduan.utils.filters import md
from daimaduan.utils.filters import ternary
from daimaduan.utils.filters import time_passed
from daimaduan.utils.filters import time_used


# set default CONFIG to config.cfg
if not os.environ.get('CONFIG', None):
    os.environ['CONFIG'] = 'custom_settings.py'


db = MongoEngine()
login_manager = LoginManager()
flask_log = Logging()
cdn = CDN()

app = Flask(__name__)
app.config.from_object('daimaduan.default_settings')
app.config.from_envvar('CONFIG')

db.init_app(app)
flask_log.init_app(app)
celery = Celery(__name__)
celery.conf.add_defaults(app.config)

from daimaduan.views.sites import site_app
from daimaduan.views.users import user_app
from daimaduan.views.pastes import paste_app
from daimaduan.views.tags import tag_app
from daimaduan.views.bookmarks import bookmark_app
Esempio n. 8
0
""" Run rodeo with a Docker specific config """

from flask.ext.cdn import CDN
from rodeo import rodeo

config = {'static-domain': 'localhost:8000',
          'storage-dir': '/home/data/',
          'dynamic-port': 5000}

if __name__ == '__main__':

    rodeo.app.config['CDN_DOMAIN'] = config['static-domain']
    CDN(rodeo.app)

    rodeo.main(config['storage-dir'],
               host='0.0.0.0',
               port=config['dynamic-port'],
               browser=False)
from rollbar.contrib.flask import report_exception
import statsd
from werkzeug.contrib.cache import MemcachedCache
from werkzeug.contrib.fixers import ProxyFix

app = Flask(__name__)

app.config.from_object('settings')

app.jinja_env.add_extension('jinja2.ext.loopcontrols')

app.wsgi_app = ProxyFix(app.wsgi_app)

db = SQLAlchemy(app)

cdn = CDN(app)

cache = MemcachedCache(app.config['MEMCACHED_URLS'])

try:
    stats = statsd.StatsClient(host=app.config['STATSD_HOST'],
                               port=app.config['STATSD_PORT'])
except socket.gaierror:
    stats = statsd.StatsClient()


def make_celery(app):
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])

    celery.conf.update(app.config)
    celery.conf.update({
Esempio n. 10
0
from daimaduan.utils.filters import datetimeformat
from daimaduan.utils.filters import md
from daimaduan.utils.filters import ternary
from daimaduan.utils.filters import time_passed
from daimaduan.utils.filters import time_used


# set default CONFIG to config.cfg
if not os.environ.get('CONFIG', None):
    os.environ['CONFIG'] = 'custom_settings.py'


db = MongoEngine()
login_manager = LoginManager()
flask_log = Logging()
cdn = CDN()

app = Flask(__name__)
app.config.from_object('daimaduan.default_settings')
app.config.from_envvar('CONFIG')

db.init_app(app)
flask_log.init_app(app)
celery = Celery(__name__)
celery.conf.add_defaults(app.config)

from daimaduan.views.sites import site_app
from daimaduan.views.users import user_app
from daimaduan.views.pastes import paste_app
from daimaduan.views.tags import tag_app
from daimaduan.views.bookmarks import bookmark_app