コード例 #1
0
ファイル: base.py プロジェクト: alexpirine/shelf-cms
 def init_db(self, db_object):
     """Init shelf with the db object"""
     if self.app is None:
         raise ValueError
     self.db = db_object
     self.db.create_all()
     make_lazy_configured(sqlalchemy.orm.mapper)
コード例 #2
0
ファイル: __init__.py プロジェクト: streamr/marvin
def create_app(config_file=None, **extra_config):
    """ Creates a WSGI app.

    :param config_file: Load config from this file.
    :param extra_config: Extra configuration values to pass to the WSGI object.
    """
    app = Flask(__name__)

    _configure_app(app, config_file, **extra_config)
    _configure_logging(app)
    _connect_extensions(app)

    # Configure lazy models
    make_lazy_configured(sqlalchemy.orm.mapper)

    _connect_blueprints(app)
    _connect_api_endpoints()
    _connect_utilities(app)

    # Import modules that connect to signals
    from . import permissions as _

    return app
コード例 #3
0
# -*- coding: utf-8 -*-
import os
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from sqlalchemy_defaults import make_lazy_configured


make_lazy_configured(
    sa.orm.mapper
)


class TestCase(object):
    def get_dns_from_driver(self, driver):
        if driver == 'postgres':
            return 'postgres://postgres@localhost/sqlalchemy_defaults_test'
        elif driver == 'mysql':
            return 'mysql+pymysql://travis@localhost/sqlalchemy_defaults_test'
        elif driver == 'sqlite':
            return 'sqlite:///:memory:'
        else:
            raise Exception('Unknown driver given: %r' % driver)

    def setup_method(self, method):
        driver = os.environ.get('DB', 'sqlite')
        dns = self.get_dns_from_driver(driver)
        self.engine = create_engine(dns)
        self.Model = declarative_base()
コード例 #4
0
ファイル: __init__.py プロジェクト: tartopum/wello
from . import config
from .config import Config
from . import cuboid_tank
from .cuboid_tank import CuboidTank
from . import cylinder_tank
from .cylinder_tank import CylinderTank
from .shared import Session, request
from . import pump_in_state
from . import tank
from . import urban_network_state
from . import water_flow_in
from . import water_flow_out
from . import water_volume

make_lazy_configured(sqlalchemy.orm.mapper)


@contextmanager
def open_session():
    """Provide a transactional scope around a series of operations."""
    session = Session()
    try:
        yield session
        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
コード例 #5
0
from flask_thumbnails_s3 import Thumbnail

from library.admin_utils import ProtectedAdminIndexView


app = Flask(__name__,
            template_folder=path.abspath(
                path.join(path.dirname(__file__), '../templates')),
            static_folder=path.abspath(
                path.join(path.dirname(__file__), '../static')))

app.config.from_object('project.settings')

db = SQLAlchemy(app)
db.Column = sqlalchemy_defaults.Column
sqlalchemy_defaults.make_lazy_configured(db.mapper)

migrate = Migrate(app, db, path.join(app.config['PROJECT_ROOT'], 'migrations'))

from accounts.models import Role, User
security = Security(app, SQLAlchemyUserDatastore(db, User, Role))

Bootstrap(app)

thumb = Thumbnail(app)

from foo.uploads import upload_sets

configure_uploads(app, upload_sets)
patch_request_class(app)
コード例 #6
0
ファイル: __init__.py プロジェクト: thusoy/blag
from flask_sqlalchemy import SQLAlchemy
from jinja2 import FileSystemLoader
from logging import getLogger
from os import path
from sqlalchemy_defaults import make_lazy_configured

import logging.config
import os
import sqlalchemy
import textwrap
import ujson as json
import yaml

from ._flask_porridge import Porridge

make_lazy_configured(sqlalchemy.orm.mapper)

db = SQLAlchemy()
login_manager = LoginManager()
principal = Principal()
porridge = Porridge()

_logger = getLogger('blag')

def create_app(**extra_config):
    app = Flask('blag')
    _configure_app(app, **extra_config)
    _init_logging(app)

    # register extensions
    db.init_app(app)
コード例 #7
0
def lazy_configured(models):
    for model in models:
        make_lazy_configured(model.__mapper__)
コード例 #8
0
from flask.ext.uploads import configure_uploads, patch_request_class
from flask_thumbnails_s3 import Thumbnail

from library.admin_utils import ProtectedAdminIndexView

app = Flask(__name__,
            template_folder=path.abspath(
                path.join(path.dirname(__file__), '../templates')),
            static_folder=path.abspath(
                path.join(path.dirname(__file__), '../static')))

app.config.from_object('project.settings')

db = SQLAlchemy(app)
db.Column = sqlalchemy_defaults.Column
sqlalchemy_defaults.make_lazy_configured(db.mapper)

migrate = Migrate(app, db, path.join(app.config['PROJECT_ROOT'], 'migrations'))

from accounts.models import Role, User

security = Security(app, SQLAlchemyUserDatastore(db, User, Role))

Bootstrap(app)

thumb = Thumbnail(app)

from foo.uploads import upload_sets

configure_uploads(app, upload_sets)
patch_request_class(app)