You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.6 KiB
77 lines
2.6 KiB
from flask import Flask
|
|
from flask_session import Session
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_bcrypt import Bcrypt
|
|
from flask_login import LoginManager
|
|
from flask_mail import Mail
|
|
from flask_migrate import Migrate
|
|
from minibase.config import AppConfig
|
|
|
|
# (DATABASE) Definition
|
|
db = SQLAlchemy()
|
|
|
|
# (PASSWORD) Hashing Module to save paswords safely
|
|
bcrypt = Bcrypt()
|
|
|
|
# (LOGIN) Login manage plugin configuration
|
|
login_manager = LoginManager()
|
|
login_manager.login_view = 'user.login' # User management (current_user)
|
|
login_manager.login_message_category = 'info' # Boostrap Info Message
|
|
|
|
# (EMAIL AGENT) Definition
|
|
mail = Mail() # So that we can send mails
|
|
|
|
# (SESSION) Starts the curren flask session
|
|
session = Session()
|
|
|
|
# Definition of custom filter for Jinja2
|
|
def get_attr(obj, attr):
|
|
print(obj)
|
|
print(attr)
|
|
return(getattr(obj, attr.strip(), None) )
|
|
|
|
def create_app():
|
|
# (APP) Definition
|
|
app = Flask(__name__)
|
|
# (APP) Configure configuration
|
|
app.config.from_object(AppConfig)
|
|
# (DATABASE) Initialisation
|
|
db.init_app(app)
|
|
# (PASSWORD) Initialisation
|
|
bcrypt.init_app(app)
|
|
# (LOGIN) Initialisation
|
|
login_manager.init_app(app)
|
|
# (EMAIL AGENT) Initialisation
|
|
mail.init_app(app)
|
|
# Session for variable manipulation on server side
|
|
|
|
# (DATABASE) Linking the app and the Database
|
|
Migrate(app, db)
|
|
|
|
# (BLUEPRINTS) Importing the blueprints.
|
|
# Include are made here to awoid the Circular import issues
|
|
from minibase.blueprints.main.routes import main
|
|
from minibase.blueprints.user.routes import user
|
|
from minibase.blueprints.errors.routes import errors
|
|
from minibase.blueprints.company.routes import company
|
|
from minibase.blueprints.geography.routes import geography
|
|
from minibase.blueprints.sensor.routes import sensor
|
|
from minibase.blueprints.database.routes import database
|
|
#from minibase.blueprints.item.routes import item
|
|
|
|
# (BLUEPRINTS) Registering the blueprints.
|
|
# Giving them theie ulr_prefixes that will define their links on the webBrowser.
|
|
app.register_blueprint(main, url_prefix='/')
|
|
app.register_blueprint(user, url_prefix='/user')
|
|
app.register_blueprint(errors, url_prefix='/errors')
|
|
app.register_blueprint(company, url_prefix='/company')
|
|
app.register_blueprint(geography, url_prefix='/geography')
|
|
app.register_blueprint(sensor, url_prefix='/sensor')
|
|
app.register_blueprint(database, url_prefix='/database')
|
|
|
|
# Addinf the custom get_attr() filter to Jinja2 template engine
|
|
app.add_template_filter(get_attr)
|
|
|
|
# (APP) Returning the initialised app
|
|
return app
|