예제 #1
0
def create_app():

    app = Flask(__name__)

    app.config['UPLOAD_DIR'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'upload')
    app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024

    app.config['DB_DIRECTORY'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database')
    app.config['DB_7Z_PATH'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database', 'permission_db.7z')
    app.config['DB_PATH'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'database', 'permission_db.db')

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DB_PATH']
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # Establish the database connection.
    db.init_app(app)

    # Create the upload directory (if not already existing).
    if not os.path.exists(app.config['UPLOAD_DIR']):
        os.makedirs(app.config['UPLOAD_DIR'])

    # Check if the database file is already extracted from the archive, otherwise extract it.
    if not os.path.isfile(app.config['DB_PATH']):
        instruction = '7z x "{0}" -o"{1}"'.format(app.config['DB_7Z_PATH'], app.config['DB_DIRECTORY'])
        subprocess.run(instruction, shell=True)

    return app
예제 #2
0
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile('config.py')
    db.init_app(app)

    app.register_blueprint(short_blueprint)
    return app
예제 #3
0
def run_jobs():
    """send sms messages due for current hour"""

    with app.app_context():
        db.init_app(app)

        now = datetime.now()
        print("Current Hour:", now.hour)
        jobs_due = Job.query.filter_by(
            time=str(now.hour) +
            ':00').all()  # TODO filter out inactive after testing is done

        # jobs_due = session.query(Job).filter_by(time=str(now.hour)+':00').options(joinedload('*')).all()

        print(jobs_due)

        for job in jobs_due:

            print("User:"******"User Phone:", job.phone,
                  "User Msg:", job.msg_txt, "Status:", job.active)

            if job.active:
                job_id = job.id
                to = job.phone
                body = job.msg_txt

                send_sms(to, body, job_id)
                # print(to, body, job_id)
                print("Sending:", job.phone, job.msg_txt, job.id)
                # send_sms(job.phone, job.msg_txt, job.id)

        db.session.commit()
def app(request):
    """Session-wide test `Flask` application."""
    settings_override = {
        'TESTING': True,
        'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI,
        #'SQLALCHEMY_TRACK_MODIFICATIONS' : False,
    }
    app = create_app(__name__, settings_override)


    # Establish an application context before running the tests.
    ctx = app.app_context()
    ctx.push()

    print("DB Fixture!")
    """Session-wide test database."""

    _db.init_app(app)
    _db.create_all()

    #db.create_all()


    def teardown():
        _db.drop_all()
        ctx.pop()
        os.unlink(TESTDB_PATH)

    request.addfinalizer(teardown)
    return app
예제 #5
0
def create_app(config):
    app = Flask(__name__)
    CORS(app)
    app.config.from_object(config)  # confi ps gress
    api.init_app(app)
    db.init_app(app)
    return app
예제 #6
0
def create_app(config_name):

    app = Flask(__name__, instance_relative_config=1)

    app.config.from_object(config_name)

    app.config.from_pyfile("config.py")

    from model import db

    db.init_app(app)

    from utilities import cache

    cache.init_app(app)

    from admin import admin

    admin.init_app(app)

    from security import security

    security.init_app(app)

    from main import main as main_blueprint

    app.register_blueprint(main_blueprint)

    return app
예제 #7
0
파일: app.py 프로젝트: Saliovin/capstone
def create_app(platform):
    app = Flask(__name__)
    app.config.from_object(app_config[platform])
    db.init_app(app)
    app.register_blueprint(harvester_blueprint, url_prefix='/harvester/')

    return app
예제 #8
0
def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = os.environ.get("FLASK_SECRET_KEY", "abcdef")
    db.init_app(app)
    with app.test_request_context():
        db.create_all()
    return app
예제 #9
0
def create_app():
    app = Flask(__name__)

    # 设置环境变量之类的东西
    app.env = os.getenv("FLASK_ENV")
    app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("SQLALCHEMY_DATABASE_URI")   # 数据库连接配置
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY")
    app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(hours=24)
    app.config["PROPAGATE_EXCEPTIONS"] = True

    # 注册蓝图
    app.register_blueprint(api)

    # 数据库连接相关
    db.init_app(app)

    # jwt相关
    jwt.init_app(app)

    # redis相关
    if not redisInit():
        raise Exception("Redis连接失败")

    # 创建表
    with app.app_context():
        db.create_all()
        db.session.commit()

    # 推送app上下文
    app.app_context().push()

    return app
def connect_to_db(app):
    """Connect the database to our Flask app."""

    # Configure to use our PstgreSQL database
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///commuknitty'
    db.app = app
    db.init_app(app)
예제 #11
0
def create_app():
    app = Flask(__name__, static_folder='static')
    CORS(app)
    app.config.from_object("config")
    db.init_app(app)
    app.register_blueprint(api_1_0.bp, url_prefix='/api/1_0')
    return app
예제 #12
0
def connect_to_db(app):
    """Connect the database to our Flask app."""

    # Configure to use postgresql database
    app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://coreyshott@localhost:5432/contributions"
    db.app = app
    db.init_app(app)
예제 #13
0
def connect_to_db(app):
    """Connecting the database to our Flask Application"""

    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.app = app
    db.init_app(app)
예제 #14
0
def connect_to_db(app):
    """Connect the database to our Flask app."""

    # Configure to use our PstgreSQL database
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///commuknitty'
    db.app = app
    db.init_app(app)
예제 #15
0
def init(configfile):
    app.config.from_pyfile('openmoves.cfg.default', silent=False)
    if configfile:
        if not os.path.exists(configfile):
            with open(configfile, 'w') as f:
                initialize_config(f)
            print("created %s" % configfile)

        app.config.from_pyfile(configfile, silent=False)
        assert app.config['SECRET_KEY']

        SESSION_VERSION = 1
        app.config['SECRET_KEY'] = "%s-%d" % (app.config['SECRET_KEY'], SESSION_VERSION)

    assert 'SQLALCHEMY_TRACK_MODIFICATIONS' not in app.config
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)

    with app.app_context():
        if db.engine.name == 'sqlite':
            db.create_all()

    Bootstrap(app)
    app_bcrypt.init_app(app)

    login_manager.init_app(app)
    login_manager.login_view = "login"

    return app
예제 #16
0
def init(configfile):
    app.config.from_pyfile('openmoves.cfg.default', silent=False)
    if configfile:
        if not os.path.exists(configfile):
            with open(configfile, 'w') as f:
                initialize_config(f)
            print("created %s" % configfile)

        app.config.from_pyfile(configfile, silent=False)
        assert app.config['SECRET_KEY']

        SESSION_VERSION = 1
        app.config['SECRET_KEY'] = "%s-%d" % (app.config['SECRET_KEY'],
                                              SESSION_VERSION)

    assert 'SQLALCHEMY_TRACK_MODIFICATIONS' not in app.config
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)

    with app.app_context():
        if db.engine.name == 'sqlite':
            db.create_all()

    Bootstrap(app)
    app_bcrypt.init_app(app)

    login_manager.init_app(app)
    login_manager.login_view = "login"

    return app
예제 #17
0
파일: app.py 프로젝트: pyfisch/oswblp
def main():
    app = Flask(__name__)
    app.config.from_envvar('OSWBLP_SETTINGS')
    app.register_blueprint(views)
    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    app.run(host='0.0.0.0')
예제 #18
0
def create_flask_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///seq.db'
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    db.init_app(app)
    app.app_context().push()
    app.url_map.strict_slashes = False
    return app
예제 #19
0
def create_app():
    app = Flask(__name__)

    configer.init_app(app)
    intercept.init_app(app)
    db.init_app(app)
    bp.init_app(app)
    return app
예제 #20
0
def connect_to_db(app, database_URI):
    """Connect the database to Flask app."""

    app.config['SQLALCHEMY_DATABASE_URI'] = database_URI
    app.config['SQLALCHEMY_ECHO'] = False
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.app = app
    db.init_app(app)
예제 #21
0
 def setUp(self):
     self.app = app.test_client()
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     db.app = app
     db.init_app(app)
     db.create_all()
예제 #22
0
def create_app():
    application = Flask(__name__)
    application.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URI
    application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.TRACK_MOD
    application.config['SECRET_KEY'] = config.SECRET_KEY
    db.init_app(application)
    ma.init_app(application)
    CORS(application)
    return application
예제 #23
0
def connect_to_test_db(app):
    """Connect the database to our Flask app."""

    # Configure to use our database.
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb'
    app.config['SQLALCHEMY_ECHO'] = False
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.app = app
    db.init_app(app)
예제 #24
0
	def connect_to_db(app):
		"""Connect the database to our Flask app"""

		app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb'
		app.config['TESTING'] = True
		app.config['SQLALCHEMY_ECHO'] = False
		app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
		db.app = app
		db.init_app(app)
예제 #25
0
def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)

    app.register_blueprint(api_blueprint, url_prefix='/api/v1')

    db.init_app(app)

    return app
예제 #26
0
def create_app():
    app = Flask(__name__)
    app.config['DEBUG'] = True
    app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///database.db"
    db.init_app(app)    
    app.register_blueprint(login_blueprint)
    app.register_blueprint(profile_blueprint)
    app.secret_key = 'terrible secret'
    return app 
예제 #27
0
def create_app(config_name):
    app.config.from_object(config[config_name])
    from model import db
    db.init_app(app)
    login_manager.init_app(app)
    from views import main

    app.register_blueprint(main)
    return app
예제 #28
0
 def create_app(self):
     self.app = create_app(PresentConfig)
     self.client = self.app.test_client()
     with self.app.app_context():
         db.init_app(self.app)
         redis_cache.init_app(self.app)
         db.create_all()
         db.session.commit()
     return self.app
예제 #29
0
def connect_to_db(app):
    """Connect the database to the Flask app."""

    # Configure to use the PstgreSQL database.
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///habot'
    app.config['SQLALCHEMY_ECHO'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.app = app
    db.init_app(app)
예제 #30
0
파일: main.py 프로젝트: mrjerr/notesite
def create_app():
    app = Flask(__name__)
    app.config.from_object('config')

    from model import db
    db.init_app(app)

    setup_views(app)

    return app
예제 #31
0
    def create_app(self):
        application = Flask(__name__)
        application.config['TESTING'] = True

        # Empty SQLite URI points to in-memory database
        application.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
        application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
        db.init_app(application)

        return application
예제 #32
0
 def setUp(self):
     """Set up database for testing purposes"""
     print "Setting up test database"
     self.app = app.test_client()
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb'
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     db.app = app
     db.init_app(app)
     db.create_all()
예제 #33
0
파일: app.py 프로젝트: lmcintyre/localizr
    def run_site(self):
        import logging
        log = logging.getLogger("werkzeug")
        log.setLevel(logging.ERROR)

        app.register_blueprint(views.blog)
        db.init_app(app)
        webbrowser.open("http://localhost:5000/welcome")
        print(f"hosting {self.blog_name} on http://localhost:5000/ !")
        app.run()
예제 #34
0
def create_app(config_filename):
    app.config.from_object(config_filename)
    global t
    if t == 0:
        app.register_blueprint(api_bp, url_prefix='/api')
        t = 1
    if config_filename != TestingConfig:
        db.init_app(app)
        redis_cache.init_app(app)
    return app
예제 #35
0
def create_app():
    logger.info(f"Starting app in {config.APP_ENV} environment")

    app = Flask(__name__)
    app.config.from_object("config")

    api.init_app(app)
    db.init_app(app)

    return app
예제 #36
0
    def setUp(self):
        """Set up database for testing purposes"""

        print "Setting up test database"
        self.app = app.test_client()
        app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres:///testdb'
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
        db.app = app
        db.init_app(app)
        db.create_all()
예제 #37
0
파일: tests.py 프로젝트: linvivian7/koi
    def setUp(self):
        """Stuff to do before every test."""

        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = os.environ['APP_SECRET']
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
        db.init_app(app)
        self.client = app.test_client()

        add_user_session(self)
        connect_to_db(app, "postgresql:///koi")
예제 #38
0
def init_db():
    # set application configuration variables
    application.config['SQLALCHEMY_DATABASE_URI'] = environ['SQLALCHEMY_DATABASE_URI']
    application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

    # required to use Flask sessions and the debug toolbar
    application.secret_key = environ['FLASK_SECRET_KEY']

    # assign database to Flask application
    db.app = application
    db.init_app(application)
예제 #39
0
 def setUp(self):
     """
     Setup a testing only database
     """
     self.app = app.test_client()
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testingdb'
     db.app = app
     db.init_app(app)
     db.create_all()
     seed_db()
예제 #40
0
 def setUp(self):
     """Set up database for testing purposes"""
     self.app = app.test_client()
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
     db.app = app
     db.init_app(app)
     db.create_all()
     print "setup ran"
     # include for test_login()
     self._add_user()
예제 #41
0
def create_app(config_object):
    _app = Flask(__name__)
    _app.register_blueprint(helloworld.blueprint)
    db.init_app(_app)

    _app.config.from_object(config_object)
    override_env_name = 'FLASK_SEED_CONFIG'
    if _app.config.from_envvar(override_env_name, silent=True):
        path = os.environ[override_env_name]
        print 'Overriding config by environment variable: %s = %s' % (override_env_name, path)

    return _app
예제 #42
0
파일: security.py 프로젝트: wushuyi/myflask
def register(app):
    if not hasattr(app, 'extensions'):
        app.extensions = {}
    if not hasattr(app.extensions, 'sqlalchemy'):
        db.init_app(app)

    security.init_app(app)

    @app.context_processor
    def security_context_processor():
        return export_processor()

    app.register_blueprint(security_page)
예제 #43
0
 def setUp(self):
     self.db_fd, self.db_filename = tempfile.mkstemp()
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////" + self.db_filename
     app.config["TESTING"] = True
     app.testing = True
     app.config["WTF_CSRF_ENABLED"] = False
     self.test_client = app.test_client()
     db.app = app
     db.init_app(app)
     with app.app_context():
         db.create_all()
     seed.load_users()
     seed.load_listings()
     seed.load_messages()
예제 #44
0
파일: __init__.py 프로젝트: briansan/inv
def create_app(conf):
  # init
  app = Flask(__name__)
  app.config.from_pyfile(conf)
  # connect model to app
  db.init_app(app)
  with app.app_context():
    db.create_all()
  # secure it
  SSLify(app)
  # register blueprints
  app.register_blueprint(api,url_prefix='/api/v1')
  app.register_blueprint(site,url_prefix='')
  return app
예제 #45
0
 def setUp(self):
     self.db_fd, self.db_filename = tempfile.mkstemp()
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////' + self.db_filename
     app.config['TESTING'] = True
     app.testing = True
     app.config['WTF_CSRF_ENABLED'] = False
     self.test_client = app.test_client()
     db.app = app
     db.init_app(app)
     with app.app_context():
         db.create_all()
     seed.load_categories()
     seed.load_providers()
     seed.load_venues()
     seed.load_experiences()
예제 #46
0
    def setUp(self):
        """
        Setup a testing only database
        """
        self.app = app.test_client()
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testingdb'
        db.app = app
        db.init_app(app)
        db.create_all()
        seed_db()

        u = User(first_name='Jane', last_name='Smith', email='*****@*****.**', username='******', password='******')
        db.session.add(u)
        db.session.commit()
        self.login('jsmith', 'test')
예제 #47
0
def create_app():
    app = Flask(__name__)
    app.secret_key = SECRET_KEY
    app.config.update({
        'SQLALCHEMY_DATABASE_URI': SQLALCHEMY_DATABASE_URI,
        'SQLALCHEMY_ECHO': SQLALCHEMY_ECHO,
        'SQLALCHEMY_TRACK_MODIFICATIONS': True
    })
    from model import db
    from .views import init_app as viewinit
    from .admin import admin
    db.init_app(app)
    viewinit(app)
    admin.init_app(app)
    login_manager.init_app(app)
    return app
예제 #48
0
    def setUp(self):
        self.app = app.test_client()
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
        db.app = app
        db.init_app(app)
        db.create_all()

        generate_example_schools()
        generate_example_users()
        generate_example_school_lists()

        # initiate session
        with self.app as c:
            with c.session_transaction() as sess:
                sess['user_id'] = '1'
예제 #49
0
def create_app(config_object):
    _app = Flask(__name__)

    for (name, bp) in blueprints.blueprints.iteritems():
        print 'load %s blueprint' % name
        _app.register_blueprint(bp.blueprint)

    db.init_app(_app)
    principal.principal.init_app(_app)
    login.login_manager.init_app(_app)

    _app.config.from_object(config_object)
    override_env_name = 'FLASK_SEED_CONFIG'
    if _app.config.from_envvar(override_env_name, silent=True):
        path = os.environ[override_env_name]
        print 'Overriding config by environment variable: %s = %s' % (override_env_name, path)

    return _app
예제 #50
0
def connect_to_db(app, db, db_name):
    """Connect the database to Flask app."""
    # Configure to use SQLite database
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_name
    db.app = app
    db.init_app(app)


    with app.app_context(): # http://stackoverflow.com/questions/19437883/when-scattering-flask-models-runtimeerror-application-not-registered-on-db-w
        # if in reseed mode, delete database so can be reseeded.
        if len(argv) > 1:
            script, mode = argv
            if mode == "reseed":
                os.remove(db_name)
        # if database doesn't exist yet, creates database
        if os.path.isfile(db_name) != True:
            db.create_all()
            logging.info("New database called '%s' created" % db_name)

        logging.info("Connected to %s" % db_name)
    return app
예제 #51
0
파일: admin.py 프로젝트: wushuyi/myflask
def register(app):
    if not hasattr(app, 'extensions'):
        app.extensions = {}
    if not hasattr(app.extensions, 'sqlalchemy'):
        db.init_app(app)
    admin.init_app(app)
예제 #52
0
def create_app(config={'MONGODB_SETTINGS': {'DB': "assignment"}}):
    app = Flask(__name__)
    app.config["MONGODB_SETTINGS"] = config['MONGODB_SETTINGS']
    app.register_blueprint(api)
    db.init_app(app)
    return app
예제 #53
0
from flask import Flask, render_template
from model import db, Cooperative

app = Flask(__name__)
app.config.from_pyfile("app_config.py")
db.init_app(app)

@app.route('/')
def hello_world():
    coops = Cooperative.query.filter(Cooperative.geo_raw_data != None).all()
    return render_template('index.html', cooperatives=coops)

@app.route('/view_coop/<int:coop_id>')
def view_coop(coop_id):
    return render_template('view_coop.html', coop=Cooperative.query.get_or_404(coop_id))


if __name__ == '__main__':
    app.run()
예제 #54
0
파일: blog.py 프로젝트: wushuyi/myflask
def register(app):
    if not hasattr(app, 'extensions'):
        app.extensions = {}
    if not hasattr(app.extensions, 'sqlalchemy'):
        db.init_app(app)
    app.register_blueprint(blog_page)
예제 #55
0
def connect_to_db(app):
    """Connect the database to our Flask app."""
    # Configure to use PostgreSQL database
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///examplerecipes'
    db.app = app
    db.init_app(app)