ciclos

ref: configuration

src/__init__.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
import locale

def as_currency(value):
    return locale.currency(value)

def create_app():
    app = Flask(__name__)

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

    # Database
    app.config['SECRET_KEY'] = '123456asckjnsac'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/ciclos_dev'
    app.jinja_env.filters['as_currency'] = as_currency

    login_manager = LoginManager()
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)

    from .types import db
    db.init_app(app)
    from .types.user import User

    @login_manager.user_loader
    def user_loader(user_id):
        return User.query.get(int(user_id))

    # Blueprints
    from .blueprints.basic import basic
    from .blueprints.auth import auth
    from .blueprints.groups import groups
    from .blueprints.products import pro as products
    from .blueprints.product_categories import product_categories
    from .blueprints.cycles import cycles
    from .blueprints.orders import orders
    app.register_blueprint(orders)
    app.register_blueprint(basic)
    app.register_blueprint(auth)
    app.register_blueprint(product_categories)
    app.register_blueprint(products)
    app.register_blueprint(groups)
    app.register_blueprint(cycles)
    app.register_blueprint(orders)

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

    return app