コード例 #1
0
ファイル: app.py プロジェクト: alexpirine/shelf-cms
def create_app():
    app = Flask(__name__)

    app.debug = True
    app.testing = False

    import config
    app.config.from_object(config)

    app.config['SHELF_PAGES'] = {
        "index": (IndexPage, IndexPageModelView),
        "contact": (ContactPage, ContactPageModelView),
    }

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

        babel = Babel(app)

        shlf = Shelf(app)
        shlf.init_db(db)

        dview = DashboardView()
        shlf.init_admin(index_view=dview)

        shlf.init_security(User, Role)

        shlf.load_plugins((
            "shelf.plugins.dashboard",
            "shelf.plugins.i18n",
            "shelf.plugins.library",
            "shelf.plugins.page",
            "shelf.plugins.preview",
            "shelf.plugins.workflow",
            "shelf.plugins.wysiwyg",
            "shelf.plugins.ecommerce",
        ))
        init_admin(shlf.admin, db.session)
        shlf.setup_plugins()

        page = shlf.get_plugin_by_class(PagePlugin)
        page.register_pages(app, shlf.db)

        init_views(app)
        init_filters(app)

    return app
コード例 #2
0
ファイル: simplest.py プロジェクト: alexpirine/shelf-cms
from flask import Flask

from shelf import LazyConfigured
from shelf import Shelf
from shelf.base import db
from shelf.security.models import User, Role
from shelf.admin.view import SQLAModelView
from sqlalchemy_defaults import Column

app = Flask(__name__)
app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///simplest.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = 'notasecret'

class Post(LazyConfigured):
    id = Column(db.Integer, primary_key=True)

    title = Column(db.Unicode(150))
    content = Column(db.UnicodeText)

with app.app_context():
    db.init_app(app)
    shlf = Shelf(app)
    shlf.init_db(db)
    shlf.init_admin()
    shlf.init_security(User, Role)
    shlf.admin.add_view(SQLAModelView(Post, db.session))

    app.run('0.0.0.0')