ciclos

ref: master

core/app.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
52
53
54
55
56
57
58
59
from flask import Flask, render_template
from flask_login import LoginManager
import locale

from core.config import read_from_config, env
from core.database import db, init_database

app = Flask(__name__)
app.secret_key = read_from_config("secret-key")

init_database()

try:
    locale.setlocale(locale.LC_ALL, read_from_config("locale"))
except:
    pass

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

from core.filters import *
app.jinja_env.filters['as_currency'] = as_currency

from .types.user import User

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

from core.blueprints.basic import basic
from core.blueprints.auth import auth
from core.blueprints.groups import groups
from core.blueprints.product_categories import product_categories
from core.blueprints.products import pro as products
from core.blueprints.cycles import cycles
from core.blueprints.orders import orders
from core.blueprints.reports import reports

app.register_blueprint(basic)
app.register_blueprint(auth)
app.register_blueprint(groups)
app.register_blueprint(product_categories)
app.register_blueprint(products)
app.register_blueprint(cycles)
app.register_blueprint(orders)
app.register_blueprint(reports)

@app.errorhandler(404)
def handle_404(e):
    return render_template("not_found.html"), 404

@app.context_processor
def inject():
    ctx = {
        'environment': env,
    }

    return ctx