Beispiel #1
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("config")

    register_babel(app)
    register_jinjia_filters(app)
    register_blueprints(app)
    register_database(app)

    create_admin(app)
    init_login(app)
    return app
Beispiel #2
0
def create_app():
    app = Flask(__name__, static_folder=static_folder)

    try:
        app.config['SQLALCHEMY_DATABASE_URI'] = os.environ[
            'OPENSHIFT_MYSQL_DB_URL'] + os.environ['OPENSHIFT_APP_NAME']
    except KeyError:
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{0}'.format(
            os.path.abspath(
                os.path.join(app.root_path, '..', 'data-dev.sqlite')))

    app.config['THEME_PATHS'] = (os.path.join(
        os.environ.get('OPENSHIFT_DATA_DIR', app.root_path), 'themes'), )

    cfg_folder = os.environ.get('OPENSHIFT_DATA_DIR', app.root_path)

    if not os.path.exists(os.path.join(cfg_folder, 'config.yml')):
        make_config(cfg_folder)
        if 'OPENSHIFT_DATA_DIR' in os.environ:
            shutil.copytree(os.path.join(app.root_path, 'static'),
                            os.path.join(cfg_folder, 'static'))
            shutil.copytree(os.path.join(app.root_path, 'themes'),
                            os.path.join(cfg_folder, 'themes'))

    with open(os.path.join(cfg_folder, 'config.yml')) as f:
        app.config.update(yaml.load(f))

    # Database / Admin
    db.init_app(app)
    themes.init_themes(app, app_identifier='WikiWizard')
    login_manager.init_app(app)
    with app.app_context():
        try:
            User.query.all()
        except (OperationalError, ProgrammingError):
            db.create_all()
            install_data()
    # From Flask-Bootstrap
    app.jinja_env.globals['bootstrap_is_hidden_field'] = is_hidden_field_filter
    app.jinja_env.filters['css_sanitized'] = css_sanitizer
    app.jinja_env.add_extension(WikiInclude)

    # URL Rules / Blueprints
    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    # Admin view
    from admin import create_admin
    create_admin(app)

    return app
Beispiel #3
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("config")

    register_babel(app)
    register_jinjia_filters(app)
    register_blueprints(app)
    register_database(app)



    create_admin(app)
    init_login(app)
    return app
Beispiel #4
0
def create_app():
    app = Flask(__name__)

    formatter = logging.Formatter(
        "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(messages)s")
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    app.logger_name = config.LOGGER_NAME
    app.logger.addHandler(handler)
    app.logger.setLevel(logging.INFO)

    app.config.from_object(config)

    # register extensions
    from fo.models import User
    from fo.models import Registration
    orm.configure_mappers()
    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)
    babel.init_app(app)

    admin = create_admin(app)
    from fo.views import blueprint

    app.register_blueprint(blueprint)
    return app
def create_app():
    app = Flask(__name__, static_folder=static_folder)

    try:
        app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['OPENSHIFT_MYSQL_DB_URL'] + os.environ['OPENSHIFT_APP_NAME']
    except KeyError:
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{0}'.format(
            os.path.abspath(os.path.join(app.root_path, '..', 'data-dev.sqlite')))

    app.config['THEME_PATHS'] = (os.path.join(os.environ.get('OPENSHIFT_DATA_DIR', app.root_path), 'themes'), )

    cfg_folder = os.environ.get('OPENSHIFT_DATA_DIR', app.root_path)

    if not os.path.exists(os.path.join(cfg_folder, 'config.yml')):
        make_config(cfg_folder)
        if 'OPENSHIFT_DATA_DIR' in os.environ:
            shutil.copytree(os.path.join(app.root_path, 'static'), os.path.join(cfg_folder, 'static'))
            shutil.copytree(os.path.join(app.root_path, 'themes'), os.path.join(cfg_folder, 'themes'))

    with open(os.path.join(cfg_folder, 'config.yml')) as f:
        app.config.update(yaml.load(f))

    # Database / Admin
    db.init_app(app)
    themes.init_themes(app, app_identifier='WikiWizard')
    login_manager.init_app(app)
    with app.app_context():
        try:
            User.query.all()
        except (OperationalError, ProgrammingError):
            db.create_all()
            install_data()
    # From Flask-Bootstrap
    app.jinja_env.globals['bootstrap_is_hidden_field'] = is_hidden_field_filter
    app.jinja_env.filters['css_sanitized'] = css_sanitizer
    app.jinja_env.add_extension(WikiInclude)

    # URL Rules / Blueprints
    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    # Admin view
    from admin import create_admin
    create_admin(app)

    return app
Beispiel #6
0
import utils_app
import application
import admin
import security
import db_api as dbapi
import os
import json
""" Argument parsing """
parser = ArgumentParser()
parser.add_argument("--port", type=int, default=80, help='port to run')
opt = parser.parse_args()
"""------------------"""

# initialize login stuff and create admin page
app, db, login_manager = application.app_db_login_initialized()
myadmin = admin.create_admin(app)


# flask-login callback
@login_manager.user_loader
def load_user(user_id):
    return application.User.query.get(user_id)


@login_manager.unauthorized_handler
def unauthorized_callback():
    flash("尚未登入,請登入後再繼續/Please login!")
    return redirect(url_for('login'))


# json parsing
from flask import render_template, request, flash, redirect, url_for
from flask.ext import wtf
from flask.ext import login
from amzstorefront import app
from amzstorefront.models import *
import admin
import store


app.register_blueprint(store.blueprint)
admin.create_admin(app)


def register_page(endpoint, template_filename):
    def render_page():
        return render_template(template_filename)
    app.add_url_rule(endpoint, endpoint.strip('/').replace('/', '_'), render_page)

register_page('/about', 'pages/about.html')
register_page('/contact', 'pages/contact.html')
register_page('/affiliates', 'pages/affiliates.html')


login_manager = login.LoginManager()
login_manager.login_view = "login"
login_manager.setup_app(app)


@login_manager.user_loader
def load_user(id):
    return User()
from flask import render_template, request, flash, redirect, url_for
from flask.ext import wtf
from flask.ext import login
from amzstorefront import app
from amzstorefront.models import *
import admin
import store

app.register_blueprint(store.blueprint)
admin.create_admin(app)


def register_page(endpoint, template_filename):
    def render_page():
        return render_template(template_filename)

    app.add_url_rule(endpoint,
                     endpoint.strip('/').replace('/', '_'), render_page)


register_page('/about', 'pages/about.html')
register_page('/contact', 'pages/contact.html')
register_page('/affiliates', 'pages/affiliates.html')

login_manager = login.LoginManager()
login_manager.login_view = "user_login"
login_manager.setup_app(app)


@login_manager.user_loader
def load_user(id):
Beispiel #9
0
        host_ip=DB_IP,
        db_name=DB_NAME,
        db_port=DB_PORT)
    db = setup_db(app, database_path)
    migrate = Migrate(app, db)
else:
    database_path = 'sqlite:////tmp/test.db'
    db = setup_db(app, database_path)
    db.drop_all()
    db.create_all()
# both bluprint is constructed different ways
app.register_blueprint(auth_blueprint(db), url_prefix='/auth')
app.register_blueprint(google_auth_blueprint(db), url_prefix='/google')
app.register_blueprint(user_blueprint, url_prefix='/user')

admin = create_admin(app, db)
# create admin user
ADMIN_EMAIL = os.getenv('admin_email', '*****@*****.**')
ADMIN_PASSWORD = os.getenv('admin_password', 'admin')
admin_user = UserModel(email=ADMIN_EMAIL,
                       name='Admin',
                       password=generate_password_hash(ADMIN_PASSWORD,
                                                       method='sha256'),
                       is_admin=True)
db.session.add(admin_user)
db.session.commit()

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