# -*- coding: utf-8 -*- """Extensions module. Each extension is initialized in the app factory located in app.py.""" from flask_bcrypt import Bcrypt from flask_cache import Cache from flask_debugtoolbar import DebugToolbarExtension from flask_login import LoginManager from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from flask_wtf.csrf import CsrfProtect from flask.ext.blogging import SQLAStorage, BloggingEngine bcrypt = Bcrypt() csrf_protect = CsrfProtect() login_manager = LoginManager() db = SQLAlchemy() migrate = Migrate() cache = Cache() debug_toolbar = DebugToolbarExtension() bloging_engine = BloggingEngine()
app.config["SECRET_KEY"] = "secret" # for WTF-forms and login app.config["BLOGGING_URL_PREFIX"] = "/blog" app.config["BLOGGING_DISQUS_SITENAME"] = "test" app.config["BLOGGING_SITEURL"] = "http://localhost:8000" app.config["BLOGGING_SITENAME"] = "My Site" app.config["BLOGGING_PERMISSIONS"] = False # Enable blogger permissions' app.config["CACHE_TYPE"] = "simple" # create cache cache = Cache(app) # extensions engine = create_engine('sqlite:////tmp/blog.db') meta = MetaData() sql_storage = SQLAStorage(engine, metadata=meta) blog_engine = BloggingEngine(app, sql_storage, cache=cache) login_manager = LoginManager(app) meta.create_all(bind=engine) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Paul Dirac" # typically the user's name @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user if hasattr(current_user, "id"):
def test_custom_md_extension(self): extn = CodeHiliteExtension({}) engine = BloggingEngine(extensions=[extn]) extns = engine.post_processor.all_extensions() self.assertEqual(len(extns), 3) self.assertTrue(isinstance(extns[-1], CodeHiliteExtension))
UserMixin, RoleMixin, login_required from flask.ext.admin import Admin from flask.ext import admin, login from flask.ext.babel import Babel from flask.ext.blogging import SQLAStorage, BloggingEngine from sqlalchemy import create_engine, MetaData app = Flask(__name__, static_url_path='/app/static') app.config.from_object('config') db = SQLAlchemy(app) # blogging engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI']) meta = MetaData() sql_storage = SQLAStorage(engine, metadata=meta) blog = BloggingEngine(app, sql_storage) meta.create_all(bind=engine) db.create_all() mail = Mail(app) babel = Babel(app) from app.admin.views import MyAdminIndexView backend = Admin(app, app.config['APP_NAME'], index_view=MyAdminIndexView(), base_template='admin.html') @app.errorhandler(404)
from flask.ext.principal import identity_changed, Identity, AnonymousIdentity, identity_loaded, \ UserNeed, RoleNeed app = Flask(__name__) app.config["SECRET_KEY"] = "secret" # for WTF-forms and login app.config["BLOGGING_URL_PREFIX"] = "/blog" app.config["BLOGGING_DISQUS_SITENAME"] = "test" app.config["BLOGGING_SITEURL"] = "http://localhost:8000" app.config["BLOGGING_SITENAME"] = "My Site" app.config["BLOGGING_PERMISSIONS"] = False # Enable blogger permissions # extensions engine = create_engine('sqlite:////tmp/blog.db') meta = MetaData() sql_storage = SQLAStorage(engine, metadata=meta) blog_engine = BloggingEngine(app, sql_storage) login_manager = LoginManager(app) meta.create_all(bind=engine) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Paul Dirac" # typically the user's name @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user