Ejemplo n.º 1
0
def create_app():
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    static_dir = os.path.join(BASE_DIR, 'static')
    templates_dir = os.path.join(BASE_DIR, 'templates')

    app = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    app.register_blueprint(blueprint=login, url_prefix='/user')
    app.register_blueprint(blueprint=classroom, url_prefix='/user')
    app.register_blueprint(blueprint=student, url_prefix='/user')
    app.register_blueprint(blueprint=role, url_prefix='/user')
    app.register_blueprint(blueprint=permissions, url_prefix='/user')
    app.register_blueprint(blueprint=user, url_prefix='/user')

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/fkquanxian'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 设置session密钥
    app.config['SECRET_KEY'] = 'secret_key'

    db.init_app(app=app)

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

    return app
Ejemplo n.º 2
0
def create_app(config_name):
    app = Flask(__name__, template_folder='static/templates')
    app.config.from_object(config[config_name])

    config[config_name].init_app(app)

    db.init_app(app)
    principals.init_app(app)

    return app
Ejemplo n.º 3
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    config[config_name].init_app(app)

    db.init_app(app)
    principals.init_app(app)

    return app
Ejemplo n.º 4
0
def create_app(configuration):
    app = Flask(__name__)
    app.config.from_object(configuration)
    app.response_class = MyResponse

    db.init_app(app)

    # Blueprints
    from app.resources.resources import bucket_list
    app.register_blueprint(bucket_list, url_prefix='/api/v1')

    # Gzip response
    compress.init_app(app)
    return app
Ejemplo n.º 5
0
def create_app(config_name):
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(app_config[config_name])
    app.config.from_pyfile('config.py')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    api_blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
    api.init_app(api_blueprint)
    api.add_namespace(bucketlists_namespace)
    api.add_namespace(auth_namespace)
    app.register_blueprint(api_blueprint)

    db.init_app(app)
    return app
Ejemplo n.º 6
0
def create_app():
    app = Flask(__name__)

    # app.config["SECRET_KEY"] = SECRET_KEY
    app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL
    app.config["SQLALCHEMY_TRACK_MODIFICATION"] = DATABASE_URL
    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(home_routes)
    # app.register_blueprint(book_routes)
    # app.register_blueprint(twit_routes)
    # app.register_blueprint(twitter_routes)
    # app.register_blueprint(stats_routes)
    return app
Ejemplo n.º 7
0
def connect_db():
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////var/clusters/test.db'
    db.init_app(app)
    with app.app_context():
        # db.drop_all() # DEBUG uncomment to reset tables for debugging
        db.create_all()
Ejemplo n.º 8
0
from gino.ext.aiohttp import Gino

from models.models import db, User

# Database Configuration
PG_URL = "postgresql://{user}:{password}@{host}:{port}/{database}".format(
    host=os.getenv("DB_HOST", "localhost"),
    port=os.getenv("DB_PORT", 5432),
    user=os.getenv("DB_USER", "postgres"),
    password=os.getenv("DB_PASSWORD", "postgres"),
    database=os.getenv("DB_DATABASE", "postgres"),
)

#INSTANTIATING WEB APP AND INITIALIZE ANOTHER STUFF
app = web.Application(middlewares=[db])
db.init_app(app, dict(dsn=PG_URL))  #Initializing db
'''
    We keep sockets stored in app so this memory strategy only works with one worker/instance, not for 
    production usage.
    If you want to use sockets in production it would be better to use PUB/SUB with Redis.
'''
app['websockets'] = []
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('./templates'))


#DEFINING VIEW FUNCTIONS
async def template_rendering(request):
    context = {'author': 'Alexis Piña'}
    return aiohttp_jinja2.render_template('home_template.html', request,
                                          context)
Ejemplo n.º 9
0
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db_env = os.environ.get("DB_PATH")
print(db_env)
db_uri = db_env
print("Database uri: ", flush=True)
print(db_uri, flush=True)

app.config["REMOTE_CONFIG_PATH"] = os.environ.get("REMOTE_CONFIG_PATH")
print("Remote config path: ", flush=True)
print(app.config.get("REMOTE_CONFIG_PATH"), flush=True)

engine = create_engine(db_uri)
app.config['SQLALCHEMY_DATABASE_URI'] = db_uri

db.init_app(app)
ma.init_app(app)

print("Initializing database...", flush=True)
# with app.app_context():
#     db.drop_all()
#     db.create_all()
#     from models import models
#     models.init_db()

print("Database initialized", flush=True)

processing.init_sessionfactory(engine)

# APIs
api.add_resource(ProcessingAPI, "/processes", "/processes")
Ejemplo n.º 10
0
app.config["SECURITY_CONFIRMABLE"] = False
app.config["SECURITY_SEND_REGISTER_EMAIL"] = False
app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512'

# pbkdf2_sha512 generates its own salt. We still need
# to provide this line to prevent a bug from happening
app.config['SECURITY_PASSWORD_SALT'] = 'xxxxxxxxxxxx' 
app.config['SECRET_KEY'] = 'FmG9yqMxVfb9aoEVpn6J'

# General Application Configuration
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['EVENT_PIC_UPLOAD_FOLDER'] = EVENT_PIC_UPLOAD_FOLDER

# Instatiate the database connection object defined
# in the models file.
db.init_app(app)
app.db = db

# Initialize Flask-Security and SQLAlchemy datastore
user_datastore = SQLAlchemyUserDatastore(db, db_user, Role)
security = Security(app, user_datastore)

# Initialize the Flask-Restful API object
api = Api(app)

# Add routes for users defined in api/user.py
api.add_resource(Login, '/user/login')
api.add_resource(UserList ,'/users')
api.add_resource(User, '/user/<user_id>')
api.add_resource(ProfilePic, '/user/<user_id>/picture')
api.add_resource(EventPic, '/event/<event_id>/picture')
Ejemplo n.º 11
0
mobileAPI.add_resource(schedulerController.GiveServerTime, '/API/getTime')
mobileAPI.add_resource(schedulerController.ChangeLightSchedule, '/API/test')
mobileAPI.add_resource(dataCollectionController.Collect, '/API/data')
mobileAPI.add_resource(cycleSettingsController.Change, '/API/toggleLight')
mobileAPI.add_resource(cycleSettingsController.UpdateCycleSettings,
                       '/API/updateCycleSettings')
mobileAPI.add_resource(cycleSettingsController.GetConfiguration,
                       '/API/getConfiguration')
mobileAPI.add_resource(cycleSettingsController.GetConfigurationAndStates,
                       '/API/loadSettings')
mobileAPI.add_resource(cycleSettingsController.GetConfigurationArduino,
                       '/API/GetConfigurationArduino')

mobileAPI.add_resource(chartController.TemperatureHumidity,
                       '/API/temperatureHumidityChart')
mobileAPI.add_resource(chartController.CycleTimeRatiosChart,
                       '/API/cycleTimeRatios')
mobileAPI.add_resource(chartController.LightTimeRatiosChart,
                       '/API/lightTimeRatios')

from models.models import db
db.init_app(application)
migrate = Migrate(application, db)

# run the app.
if __name__ == "__main__":
    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    application.debug = False
    application.run()