Пример #1
0
    def _init_app(self):
        if not hasattr(self.app, 'extensions'):
            self.app.extensions = dict()

        plumbums = self.app.extensions.get('plumbum', [])

        for p in plumbums:
            if p.endpoint == self.endpoint:
                raise Exception('Cannot have two Plumbum() instance with same '
                                'endpoint name.')
            if p.url == self.url and p.subdomain == self.subdomain:
                raise Exception('Cannot assign two Plumbum() instances with '
                                'same URL and subdomain to the same '
                                'application.')

        plumbums.append(self)
        self.app.extensions['plumbum'] = plumbums

        # Initialize Webpack plugin
        # FIXME: Hardcoded, move to appropiate place
        self.app.config.update({
            'WEBPACK_MANIFEST_PATH':
            '{}/static/webpack/manifest.json'.format(CURRENT_PATH),
        })
        webpack = Webpack()
        webpack.init_app(self.app)

        if self.app.debug:
            self._attach_show_urls_view()
Пример #2
0
def create_app():
    app = Flask(__name__,
                static_folder='build/public/',
                static_url_path='/assets')
    app.config['SECRET_KEY'] = 'sekrit!'

    app.config['WEBPACK_MANIFEST_PATH'] = os.path.abspath(
        './brigade/build/manifest.json')
    webpack = Webpack()
    webpack.init_app(app)

    if 'SERVER_NAME' in os.environ:
        app.config['SERVER_NAME'] = os.environ['SERVER_NAME']
    if 'SITEMAP_URL_SCHEME' in os.environ:
        app.config['SITEMAP_URL_SCHEME'] = os.environ['SITEMAP_URL_SCHEME']

    app.register_blueprint(brigade)
    app.register_blueprint(filters)
    app.register_blueprint(sitemap_blueprint)

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.html'), 404

    return app
Пример #3
0
def test_nested_asset_map_missing_public_path():
    path = os.path.abspath(
        os.path.join(__dirname, "nested_asset_map_missing_public_path.json"))
    app = Flask("test_app")
    app.config["WEBPACK_MANIFEST_PATH"] = path
    webpack = Webpack()
    webpack.init_app(app)
    with app.app_context():
        rendered = render_template_string('{{ asset_url_for("temp.js") }}')
    assert rendered == "//localhost:8080/temp.js"
Пример #4
0
def make_app():
    webpack = Webpack()
    app = Flask(__name__, template_folder='static/')

    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNECTION
    app.config['WEBPACK_MANIFEST_PATH'] = '../static/manifest.json'

    webpack.init_app(app)

    if config.SSL != 'NO_SSL':
        flask_sslify.SSLify(app)
    register_user_routes(app)
    register_search_routes(app)
    register_conversation_routes(app)
    register_share_routes(app)
    register_survey_routes(app)
    register_email_routes(app)
    register_statistics_routes(app)

    @app.teardown_appcontext
    def close_db_connection(exception):
        store.session.remove()

    @app.route('/static/js/<path:filename>')
    def js_static(filename):
        return send_from_directory(app.root_path + '/static/js/', filename)

    @app.route('/static/fonts/<path:filename>')
    def fonts_static(filename):
        return send_from_directory(app.root_path + '/static/fonts/', filename)

    @app.route('/static/css/<path:filename>')
    def css_static(filename):
        return send_from_directory(app.root_path + '/static/css/', filename)

    @app.route('/static/templates/footer.html')
    def footer_template():
        return render_template('templates/footer.html', config=config)

    @app.route('/static/templates/<path:filename>')
    def templates_static(filename):
        return send_from_directory(app.root_path + '/static/templates/',
                                   filename)

    @app.route('/')
    def index():
        logger.debug('rendering index')
        return render_template('index.html', config=config)

    return app
Пример #5
0
def make_app():
    webpack = Webpack()
    app = Flask(__name__, template_folder='static/')

    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNECTION
    app.config['WEBPACK_MANIFEST_PATH'] = '../static/manifest.json'

    webpack.init_app(app)

    if config.SSL != 'NO_SSL':
        flask_sslify.SSLify(app)
    register_user_routes(app)
    register_search_routes(app)
    register_conversation_routes(app)
    register_share_routes(app)
    register_survey_routes(app)
    register_email_routes(app)
    register_statistics_routes(app)

    @app.teardown_appcontext
    def close_db_connection(exception):
        store.session.remove()

    @app.route('/static/js/<path:filename>')
    def js_static(filename):
        return send_from_directory(app.root_path + '/static/js/', filename)

    @app.route('/static/fonts/<path:filename>')
    def fonts_static(filename):
        return send_from_directory(app.root_path + '/static/fonts/', filename)

    @app.route('/static/css/<path:filename>')
    def css_static(filename):
        return send_from_directory(app.root_path + '/static/css/', filename)

    @app.route('/static/templates/footer.html')
    def footer_template():
        return render_template('templates/footer.html', config=config)

    @app.route('/static/templates/<path:filename>')
    def templates_static(filename):
        return send_from_directory(app.root_path + '/static/templates/', filename)

    @app.route('/')
    def index():
        logger.debug('rendering index')
        return render_template('index.html', config=config)

    return app
Пример #6
0
def create_app():
    # __version__ = pkg_resources.require("atmi")[0].version

    flask_app = Flask(__name__)
    flask_app.debug = (('FLASK_ENV' in environ)
                       and (environ['FLASK_ENV'] == 'development'))
    webpack = Webpack()
    # flask_app.config.from_object(config)
    flask_app.config["WEBPACK_MANIFEST_PATH"] = path.join(
        here, "manifest.json")
    webpack.init_app(flask_app)
    setup_route_map(flask_app, here)
    setup_log(flask_app)
    flask_app.url_map.strict_slashes = False
    return flask_app
Пример #7
0
def test_flat_asset_map_renamed_public_path():
    path = os.path.abspath(
        os.path.join(__dirname, "flat_asset_map_renamed_public_path.json"))
    app = Flask("test_app")
    app.config["WEBPACK_MANIFEST_PATH"] = path
    webpack = Webpack()
    webpack.init_app(app)

    with app.app_context():
        r1 = render_template_string('{{ asset_url_for("foo") }}')
        r2 = render_template_string('{{ asset_url_for("bar.js") }}')
    e1 = "//localhost:8080/foo.h4sh3d.js"
    e2 = "//localhost:8080/completely-different.hashed.js"
    assert r1 == e1
    assert r2 == e2
Пример #8
0
def register_extensions(app):
  from flask_webpack import Webpack
  webpack = Webpack()
  webpack.init_app(app)

  from security import authenticate, identity, jwt_error_handler, jwt_payload_callback
  from flask_jwt import JWT
  jwt = JWT(app, authentication_handler=authenticate, identity_handler=identity)
  jwt.jwt_error_callback = jwt_error_handler
  jwt.jwt_payload_callback = jwt_payload_callback

  from models import db
  db.init_app(app)

  print "app.debug %s" % app.debug
  print "app.config['SECRET_KEY'] %s" % app.config['SECRET_KEY']
Пример #9
0
def create_app(config=None):
    """
    Configure app object blueprints and global variables.
    """

    app = configure_app(Flask(__name__), config)

    # setup webpack for assets
    webpack = Webpack()
    webpack.init_app(app)

    # setup flask-login
    login_manager.init_app(app)
    login_manager.view = 'login.user_login'

    # setup flask blueprints
    configure_blueprints(app)

    return app
Пример #10
0
def create_app():
    app = Flask(__name__, static_folder='build/public/', static_url_path='/assets')
    app.config['SECRET_KEY'] = 'sekrit!'
    app.config['WEBPACK_MANIFEST_PATH'] = detect_webpack_manifest_path('./brigade/build/manifest.json')

    webpack = Webpack()
    webpack.init_app(app)

    if 'SERVER_NAME' in os.environ:
        app.config['SERVER_NAME'] = os.environ['SERVER_NAME']
    if 'SITEMAP_URL_SCHEME' in os.environ:
        app.config['SITEMAP_URL_SCHEME'] = os.environ['SITEMAP_URL_SCHEME']

    app.register_blueprint(brigade)
    app.register_blueprint(filters)
    app.register_blueprint(sitemap_blueprint)

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.html'), 404

    return app
Пример #11
0
    def _create_app(self):
        app = Flask(__name__)

        self._load_config(app)
        self._register_path(app)

        # use template pug(jade)
        app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

        # use webpack
        webpack = Webpack()
        webpack.init_app(app)

        # routing
        register_routes(app)

        # init db
        init_db(app)

        toolbar = DebugToolbarExtension()
        toolbar.init_app(app)

        return app
Пример #12
0

# configuration
DATABASE = '/tmp/dubhacks_collector.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = '******'
PASSWORD = '******'

# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)
# app.secret_key = 'some key for session'
webpack = Webpack()

webpack.init_app(app)

def connect_db():
    return sqlite3.connect(app.config['DATABASE'])

def init_db():
    with closing(connect_db()) as db:
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()

def root_dir():  # pragma: no cover
    print os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "app", "src"))
    return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "app", "src"))

def get_file(filename):  # pragma: no cover
Пример #13
0
# from flask_migrate import Migrate
# from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine
from py import main, app, socketio, redis
from py.app_controller import SceneBuilder as sb
from threading import Timer, Lock

webpack = Webpack()

app = Flask(__name__)
params = {'DEBUG': True, 'WEBPACK_MANIFEST_PATH': './build/manifest.json'}

app.config.update(params)

socket_ = SocketIO(app, async_mode=None)
webpack.init_app(app)

mimetypes.add_type('application/javascript', '.mjs')

thread = None
# thread_lock = Lock()
# socketio = SocketIO(app, async_mode=None)
# redis = Redis(host='redis', port=6379)

database_uri = 'postgresql+psycopg2://{dbuser}:{dbpass}@{dbhost}:{dbport}/{dbname}'.format(
    dbuser=os.environ['DBUSER'],
    dbpass=os.environ['DBPASS'],
    dbhost=os.environ['DBHOST'],
    dbname=os.environ['DBNAME'],
    dbport=os.environ['DBPORT'])
db = create_engine(database_uri)
Пример #14
0
                        'fk': 'fk_%(table_name)s_%(column_0_name)s',
                        'ix': 'ix_%(table_name)s_%(column_0_name)s',
                        'uq': 'uq_%(table_name)s_%(column_0_name)s',
                        'ck': 'ck_%(table_name)s_%(column_0_name)s',
                    }))

MIGRATE: Migrate = Migrate(APP, DB)
BCRYPT: Bcrypt = Bcrypt(APP)

# Setup JWT
JWT: JWTManager = JWTManager(APP)

# Setup Headers
CORS(APP)

WEBPACK.init_app(APP)

# Setup Celery
# pylint: disable=C0413
from .tasks import make_celery
celery = make_celery(APP)

# Import LoginProviders
# pylint: disable=C0413
from . import auth_providers

# pylint: disable=C0413
from . import db_models
# pylint: disable=C0413
from . import routes
# pylint: disable=C0413
Пример #15
0
def make_app():
    cors = CORS(origins=[
        'https://app.communityshare.us:443', # production app
        'http://communityshare.localhost:5000', # local dev angular app
        'http://communityshare.localhost:8000', # local dev elm app
        'https://dmsnell.github.io/cs-elm/', # live elm app
    ])
    compress = Compress()
    webpack = Webpack()
    app = Flask(__name__, template_folder='../static/')
    app.response_class = JsonifyDictResponse

    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNECTION
    app.config['WEBPACK_ASSETS_URL'] = config.WEBPACK_ASSETS_URL
    app.config['WEBPACK_MANIFEST_PATH'] = config.WEBPACK_MANIFEST_PATH

    cors.init_app(app)
    compress.init_app(app)
    webpack.init_app(app)

    if config.SSL != 'NO_SSL':
        flask_sslify.SSLify(app)
        app.wsgi_app = ReverseProxied(app.wsgi_app)

    register_user_routes(app)
    register_search_routes(app)
    register_conversation_routes(app)
    register_share_routes(app)
    register_survey_routes(app)
    register_email_routes(app)
    register_statistics_routes(app)

    community_share.api.register_routes(app)

    @app.teardown_appcontext
    def close_db_connection(exception):
        store.session.remove()

    @app.errorhandler(BadRequest)
    def handle_bad_request(error):
        return str(error), HTTPStatus.BAD_REQUEST

    app.errorhandler(Unauthorized)(jsonify_with_code(HTTPStatus.UNAUTHORIZED))
    app.errorhandler(Forbidden)(jsonify_with_code(HTTPStatus.FORBIDDEN))
    app.errorhandler(NotFound)(jsonify_with_code(HTTPStatus.NOT_FOUND))
    app.errorhandler(InternalServerError)(jsonify_with_code(HTTPStatus.INTERNAL_SERVER_ERROR))

    @app.route('/static/build/<path:filename>')
    def build_static(filename):
        return send_from_directory(
            app.root_path + '/../static/build/',
            filename,
            cache_timeout=YEAR_IN_SECONDS,
        )

    @app.route('/static/js/<path:filename>')
    def js_static(filename):
        return send_from_directory(app.root_path + '/../static/js/', filename)

    @app.route('/static/fonts/<path:filename>')
    def fonts_static(filename):
        return send_from_directory(app.root_path + '/../static/fonts/', filename)

    @app.route('/static/css/<path:filename>')
    def css_static(filename):
        return send_from_directory(app.root_path + '/../static/css/', filename)

    @app.route('/static/templates/footer.html')
    def footer_template():
        return render_template('templates/footer.html', config=config)

    @app.route('/static/templates/<path:filename>')
    def templates_static(filename):
        return send_from_directory(app.root_path + '/../static/templates/', filename)

    @app.route('/')
    def index():
        logger.debug('rendering index')
        return render_template('index.html', config=config)

    return app
Пример #16
0
def make_app():
    cors = CORS(origins=[
        'https://app.communityshare.us:443',  # production app
        'http://communityshare.localhost:5000',  # local dev angular app
        'http://communityshare.localhost:8000',  # local dev elm app
        'https://dmsnell.github.io/cs-elm/',  # live elm app
    ])
    compress = Compress()
    webpack = Webpack()
    app = Flask(__name__, template_folder='../static/')

    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_CONNECTION
    app.config['WEBPACK_ASSETS_URL'] = config.WEBPACK_ASSETS_URL
    app.config['WEBPACK_MANIFEST_PATH'] = config.WEBPACK_MANIFEST_PATH

    cors.init_app(app)
    compress.init_app(app)
    webpack.init_app(app)

    if config.SSL != 'NO_SSL':
        flask_sslify.SSLify(app)
        app.wsgi_app = ReverseProxied(app.wsgi_app)

    register_user_routes(app)
    register_search_routes(app)
    register_conversation_routes(app)
    register_share_routes(app)
    register_survey_routes(app)
    register_email_routes(app)
    register_statistics_routes(app)

    community_share.api.register_routes(app)

    @app.teardown_appcontext
    def close_db_connection(exception):
        store.session.remove()

    @app.errorhandler(BadRequest)
    def handle_bad_request(error):
        return str(error), HTTPStatus.BAD_REQUEST

    @app.route('/static/build/<path:filename>')
    def build_static(filename):
        return send_from_directory(
            app.root_path + '/../static/build/',
            filename,
            cache_timeout=YEAR_IN_SECONDS,
        )

    @app.route('/static/js/<path:filename>')
    def js_static(filename):
        return send_from_directory(app.root_path + '/../static/js/', filename)

    @app.route('/static/fonts/<path:filename>')
    def fonts_static(filename):
        return send_from_directory(app.root_path + '/../static/fonts/',
                                   filename)

    @app.route('/static/css/<path:filename>')
    def css_static(filename):
        return send_from_directory(app.root_path + '/../static/css/', filename)

    @app.route('/static/templates/footer.html')
    def footer_template():
        return render_template('templates/footer.html', config=config)

    @app.route('/static/templates/<path:filename>')
    def templates_static(filename):
        return send_from_directory(app.root_path + '/../static/templates/',
                                   filename)

    @app.route('/')
    def index():
        logger.debug('rendering index')
        return render_template('index.html', config=config)

    return app