Пример #1
0
def create_app(object_name, env):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['ENV'] = env

    # Initialize Jinja custom filters
    import filters
    filters.init_app(app)

    # register our blueprints
    from app.blueprints import main
    app.register_blueprint(main)
    
    @app.errorhandler(500)
    def error_handler_500(e):
        return render_template('500.html'), 500

    @app.errorhandler(404)
    def error_handler_404(e):
        return render_template('404.html'), 404

    return app
Пример #2
0
def create_app():
    app = Flask(__name__)
    app.config['DEBUG'] = True
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///stackquery.db'
    app.secret_key = 'why would I tell you my secret key?'

    # db.init_app(app)
    filters.init_app(app)
    app.register_blueprint(dashboard)
    app.register_blueprint(rest_api)
    app.register_blueprint(report_rest_api)
    app.register_blueprint(custom_report)

    return app
Пример #3
0
def create_app(object_name, env):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['ENV'] = env

    #init SQLAlchemy
    db.init_app(app)
    db.Model = Base

    #Register Mail Service
    mail.init_app(app)

    # Initialize Jinja custom filters
    import filters
    filters.init_app(app)

    # Use Flask-Login to track current user in Flask's sessions
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'

    # register our blueprints
    from app.blueprints import main, auth, orgs, donors
    app.register_blueprint(main)
    app.register_blueprint(auth)
    app.register_blueprint(orgs)
    app.register_blueprint(donors)
    
    @app.errorhandler(500)
    def error_handler_500(e):
        return render_template('500.html'), 500

    @app.errorhandler(404)
    def error_handler_404(e):
        return render_template('404.html'), 404

    return app
Пример #4
0
from unipath import Path
import bleach
import filters

TEMPLATE_DIR = Path(__file__).ancestor(1).child("templates")

app = FlaskAPI(__name__, template_folder=TEMPLATE_DIR)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
app.config['SECRET_KEY'] = 'you-will-never-guess'
db = SQLAlchemy(app)

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'

filters.init_app(app)


class LoginForm(Form):
    username = TextField('username', validators = [Required()])


class User(db.Model):

    __tablename__ = "user"
    id = Column(Integer, primary_key=True)
    username = Column(String(64), unique=True)
    books = db.relationship('Book', backref='owner', lazy='dynamic')

    def is_authenticated(self):
        return True
Пример #5
0
from unipath import Path
import bleach
import filters

TEMPLATE_DIR = Path(__file__).ancestor(1).child("templates")

app = FlaskAPI(__name__, template_folder=TEMPLATE_DIR)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
app.config['SECRET_KEY'] = 'you-will-never-guess'
db = SQLAlchemy(app)

lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'

filters.init_app(app)


class LoginForm(Form):
    username = TextField('username', validators=[Required()])


class User(db.Model):

    __tablename__ = "user"
    id = Column(Integer, primary_key=True)
    username = Column(String(64), unique=True)
    books = db.relationship('Book', backref='owner', lazy='dynamic')

    def is_authenticated(self):
        return True