Esempio n. 1
0
def create_app():
    # Creating an instance of the Flask class
    app = Flask(__name__)
    # Pulling in configuration of database
    app.config.from_pyfile('config.cfg')
    db.init_app(app)
    # Registering blueprint for routes in flask
    app.register_blueprint(routes_blueprint)
    return app
Esempio n. 2
0
 def __init__(self,views,database_uri='sqlite:///:memory:',mqtt_host="localhost"):
     self.app = Flask(__name__)
     self.views = views
     self.mqtt_host = mqtt_host
     self.app.config['SQLALCHEMY_DATABASE_URI'] = database_uri
     self.app.config['SQLALCHEMY_ECHO'] = False
     db.init_app(self.app)
     self.register_views()
     @self.app.route('/')
     def index():
         return render_template('index.html', title="Sensor Central",views=self.views)
     @self.app.route('/index')
     def index2():
         return redirect(url_for('/'))
Esempio n. 3
0
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile(os.path.abspath('app.cfg'))

    # Database initialize with app
    db.init_app(app)
    session = Session(app)
    session.app.session_interface.db.create_all()

    # deal with database
    # with app.app_context():
    #     db.drop_all()
    #     db.create_all()

    return app
Esempio n. 4
0
def create_app():
    logger.info("Creating Flask init_app")
    app = Flask(__name__)
    app.config.from_pyfile('config.py')
    CORS(app)
    with app.app_context():
        db.init_app(app)
    flask_admin = Admin(app)
    with app.test_request_context():
        from database.models import Users, Router, Sensor, Warnings
        flask_admin.add_view(ModelView(Users, db.session))
        flask_admin.add_view(ModelView(Router, db.session))
        flask_admin.add_view(ModelView(Sensor, db.session))
        flask_admin.add_view(ModelView(Warnings, db.session))
        register_blueprints(app)
        db.create_all()
        from MQTT.mqtt_client import client
        from handlers.database_handler import DatabaseHandler
        channels = DatabaseHandler().get_router_channels()
        for ch in channels[:]:
            client.subscribe(ch)
            print("MQTT: Subscribing to: " + str(ch))
        client.loop_start()
    return app
Esempio n. 5
0
File: wicm.py Progetto: T-NOVA/WICM
    config.get('opendaylight', 'username'),
    config.get('opendaylight', 'password')
))

vtn = VtnWrapper(
    config.get('opendaylight', 'host'),
    config.get('opendaylight', 'port'),
    config.get('opendaylight', 'username'),
    config.get('opendaylight', 'password')
)


app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = mysql_connect
app.config['SQLALCHEMY_POOL_RECYCLE'] = 299  # compatibility with MariaDB
db.init_app(app)


@app.route('/nap', methods=['POST', 'GET', 'DELETE'], strict_slashes=False)
@app.route('/nap/<string:mkt_id>', methods=['GET', 'DELETE'],
           strict_slashes=False)
def nap_request(mkt_id=None):

    if request.method == 'POST':
        nap_request = request.json
        logger.info('Request to create NAP: {}'.format(nap_request))

        client_mkt_id = nap_request['nap']['client_mkt_id']
        mkt_id = nap_request['nap']['mkt_id']
        ce = (nap_request['nap']['switch'], nap_request['nap']['ce_port'],
              nap_request['nap']['ce_transport']['vlan_id'])
Esempio n. 6
0
from werkzeug.utils import secure_filename

from database.database import db, init_database
import datetime
import locale

locale.setlocale(locale.LC_ALL, 'fr_FR')

from database.models import Product, User, Reservation

app = flask.Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///database/database.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = "secret_key1234"

db.init_app(app)

with app.test_request_context():
    init_database()


def save_object_to_db(db_object):
    db.session.add(db_object)
    db.session.commit()


def remove_object_from_db(db_object):
    db.session.delete(db_object)
    db.session.commit()

Esempio n. 7
0
def initialize_extension(app):
    generate_routes(app)
    db.init_app(app)
    ma.init_app(app)
    migrate = Migrate(app, db, compare_type=True)
Esempio n. 8
0
def create_app():
    app = Flask(__name__)
    app.config.from_object('src.config.Config')
    app.register_blueprint(auth_bp, url_prefix='/auth')
    db.init_app(app)
    return app