예제 #1
0
    db_path = os.path.join(app.root_path, 'webapp.sqlite')
    app.config.update(dict(
        SQLALCHEMY_DATABASE_URI='sqlite:////' + db_path
    ))

db = SQLAlchemy()

## Initialize database settings
#
with app.test_request_context():

    from account.models import User
    db.init_app(app)

    # Create a test user for testing
    auser = User.create(username='******', password='******',
        firstname='Mr.', middlename='', lastname='Tester', email='*****@*****.**')
    if auser:
        # If this user is being registered for the first time.
        auser.save()

## Blueprint setup
#
app.register_blueprint(account_views, url_prefix='/account')
app.register_blueprint(facade_views, url_prefix='')
app.register_blueprint(main_views,url_prefix='/main')

## Flask-Login Configuration
#
login_manager = LoginManager()
login_manager.session_protection = "strong"
login_manager.init_app(app)
예제 #2
0
def create_app(RDBMS_TYPE):
    # create our little application :)
    app = Flask(__name__)

    ## Configure app
    #
    app.config.from_object(__name__)
    # Load default config and override config from an environment variable
    app.config.update(
        dict(SECRET_KEY='B1Xp83k/4qY1S~GIH!jnM]KES/,?CT',
             USERNAME='******',
             PASSWORD='******',
             SQLALCHEMY_TRACK_MODIFICATIONS=False,
             WEBAPP_NAME='Flask Scaffolding'))
    app.config.from_envvar('TRACKERAPP_SETTINGS', silent=True)

    ## Database related
    #
    # If you are using
    if RDBMS_TYPE == 'postgresql':
        app.config['SQLALCHEMY_DATABASE_URI'] = \
            'postgresql+psycopg2://pdbuser:pdbuser@localhost:5432/tracker_monitoring'

    else:  # Default is sqlite
        # Sqlite settings
        #
        db_path = os.path.join(app.root_path, 'webapp.sqlite')
        app.config.update(dict(SQLALCHEMY_DATABASE_URI='sqlite:////' +
                               db_path))

    db = SQLAlchemy()

    ## Initialize database settings
    #
    with app.test_request_context():

        from account.models import User
        db.init_app(app)

        # Create a test user for testing
        auser = User.create(username='******',
                            password='******',
                            firstname='Mr.',
                            middlename='',
                            lastname='Tester',
                            email='*****@*****.**')
        if auser:
            # If this user is being registered for the first time.
            auser.save()

    ## Blueprint setup
    #
    app.register_blueprint(account_views, url_prefix='/account')
    app.register_blueprint(facade_views, url_prefix='')
    app.register_blueprint(main_views, url_prefix='/main')

    ## Flask-Login Configuration
    #
    login_manager = LoginManager()
    login_manager.session_protection = "strong"
    login_manager.init_app(app)
    login_manager.login_view = '/account/login'

    # Required method to connect Flask-Login with custom User class
    @login_manager.user_loader
    def load_user(username):
        print 'load_user - userid', username
        return User.get_with_username(username)

    return app