def _create_blogging_engine(self): cache = Cache(self.app, config={"CACHE_TYPE": "simple"}) return BloggingEngine(self.app, self.storage, cache=cache)
with app.app_context(): blog_sql_storage = SQLAStorage(db=db) blog_login_manager = LoginManager(app) blog_login_manager.session_protection = 'strong' blog_login_manager.login_view = 'login' blog_login_manager.login_message = 'Please enter your account' blog_login_manager.init_app(app) db.create_all() blog_extns = [ 'markdown.extensions.extra', 'markdown.extensions.codehilite', 'markdown.extensions.tables', 'markdown.extensions.toc' ] blog_engine = BloggingEngine(app, blog_sql_storage, extensions=blog_extns) from flask_blogging.sqlastorage import Post, Tag @blog_login_manager.user_loader @blog_engine.user_loader def load_user(user_id): user = User.query.filter_by(id=user_id).first() return user @app.route("/") def index(): return redirect("/blog/")
def _create_blogging_engine(self): return BloggingEngine(self.app, self.storage)
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 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))
app.config["BLOGGING_SITENAME"] = "My Site" app.config["BLOGGING_TWITTER_USERNAME"] = "******" app.config["BLOGGING_ALLOW_FILEUPLOAD"] = True app.config["FILEUPLOAD_IMG_FOLDER"] = "fileupload" app.config["FILEUPLOAD_PREFIX"] = "/fileupload" app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"] # extensions """Google Cloud Storage configuration docs: https://github.com/Speedy1991/Flask-FileUpload/tree/master/doc/google_cloud_storage.md """ gcstorage = GoogleCloudStorage(app) file_upload = FlaskFileUpload(app, storage=gcstorage) gc_datastore = GoogleCloudDatastore() blog_engine = BloggingEngine(app, gc_datastore, file_upload=file_upload) login_manager = LoginManager(app) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Paul Dirac" # typically the user's name @login_manager.user_loader @blog_engine.user_loader def load_user(user_id): return User(user_id)
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
def configure_blogging(app): 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:8989" app.config["BLOGGING_SITENAME"] = "BieFeNg" app.config["BLOGGING_KEYWORDS"] = ["blog", "meta", "keywords"] app.config["FILEUPLOAD_IMG_FOLDER"] = "fileupload" app.config["FILEUPLOAD_PREFIX"] = "/fileupload" app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"] with app.app_context(): sql_storage = SQLAStorage(db=db) blog_engine = BloggingEngine(app=None, storage=sql_storage) login_manager = LoginManager(app) # blog_engine.init_app(app, sql_storage) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Paul Dirac" # typically the user's name @login_manager.user_loader @blog_engine.user_loader def load_user(user_id): return User(user_id) index_template = """ <!DOCTYPE html> <html> <head> </head> <body> {% if current_user.is_authenticated %} <a href="/logout/"> Logout </a> {% else %} <a href="/login/"> Login </a> {% endif %}   <a href="/blog/"> Blog </a>   <a href="/blog/sitemap.xml">Sitemap</a>   <a href="/blog/feeds/all.atom.xml">ATOM</a>   <a href="/fileupload/">FileUpload</a> </body> </html> """ @app.route("/") def index(): return render_template_string(index_template) @app.route("/login/") def login(): user = User("testuser") login_user(user) return redirect("/blog") @app.route("/logout/") def logout(): logout_user() return redirect("/")
from flask_sslify import SSLify from flask_sqlalchemy import SQLAlchemy from sqlalchemy import MetaData from flask_mail import Mail from wtforms.fields import HiddenField from config import config db = SQLAlchemy() from app.models import User, Answer, Sentence, Quiz, Score, Topic, Product, Purchase, Comment, Activity migrate = Migrate() login_manager = LoginManager() principal = Principal() mail = Mail() blog_engine = BloggingEngine() misaka = Misaka( app=None, renderer=None, strikethrough=True, underline=True, tables=True, wrap=True ) metadata = MetaData() def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app)
youdea_app = Flask(__name__) youdea_app.config["SECRET_KEY"] = "secret" # for WTF-forms and login youdea_app.config["BLOGGING_URL_PREFIX"] = "/blog" youdea_app.config["BLOGGING_DISQUS_SITENAME"] = "test" youdea_app.config["BLOGGING_SITEURL"] = "http://localhost:8000" youdea_app.config["BLOGGING_SITENAME"] = "My Site" youdea_app.config["BLOGGING_TWITTER_USERNAME"] = "******" youdea_app.config["FILEUPLOAD_IMG_FOLDER"] = "fileupload" youdea_app.config["FILEUPLOAD_PREFIX"] = "/fileupload" youdea_app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"] # extensions engine = create_engine('sqlite:////tmp/blog.db') meta = MetaData() sql_storage = SQLAStorage(engine, metadata=meta) blog_engine = BloggingEngine(youdea_app, sql_storage) login_manager = LoginManager(youdea_app) meta.create_all(bind=engine) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "John Doe" # For now ... @login_manager.user_loader @blog_engine.user_loader def load_user(user_id): return User(user_id)
# app.config["BLOGGING_DISQUS_SITENAME"] = "test" app.config["BLOGGING_SITEURL"] = "http://localhost:8000" app.config["BLOGGING_SITENAME"] = "Jeremy Clewell" # app.config["BLOGGING_TWITTER_USERNAME"] = "******" app.config["FILEUPLOAD_S3_BUCKET"]='jeremyclewell-site' app.config["FILEUPLOAD_PREFIX"] = "/upload" app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"] app.config["BLOGGING_ESCAPE_MARKDOWN"] = False app.config["BLOGGING_GOOGLE_ANALYTICS"] = "UA-15169356-1" # extensions s3storage = S3Storage(app) file_upload = FlaskFileUpload(app, storage=s3storage) dyn_storage = DynamoDBStorage(endpoint_url="https://dynamodb.us-east-1.amazonaws.com") blog_engine = BloggingEngine(app, dyn_storage, file_upload=file_upload, extensions=[extn1, extn3, extn4]) login_manager = LoginManager(app) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Jeremy Clewell" # typically the user's name @login_manager.user_loader @blog_engine.user_loader def load_user(user_id): return User(user_id)
from flask_sqlalchemy import SQLAlchemy from flask_blogging import BloggingEngine, SQLAStorage #Application Confirigation object from config import Config #Module Metadata __version__ = '0.1d' #Flask Extentions Objects mail = Mail() moment = Moment() db = SQLAlchemy() migrate = Migrate() bootstrap = Bootstrap() blogging = BloggingEngine() login = LoginManager() login.login_view = 'auth.login' login.login_message = 'Please log in for further access.' login.session_protection = 'strong' def create_app(appConfig=Config): app = Flask(__name__) app.config.from_object(appConfig) db.init_app(app) migrate.init_app(app, db) login.init_app(app) mail.init_app(app) bootstrap.init_app(app)
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"] = "" app.config["BLOGGING_SITENAME"] = "My Site" app.config["BLOGGING_ALLOW_FILEUPLOAD"] = True app.config["FILEUPLOAD_S3_BUCKET"] = 'quandldata' app.config["FILEUPLOAD_PREFIX"] = "/upload" app.config["FILEUPLOAD_ALLOWED_EXTENSIONS"] = ["png", "jpg", "jpeg", "gif"] # extensions s3storage = S3Storage(app) file_upload = FlaskFileUpload(app, storage=s3storage) dyn_storage = DynamoDBStorage(endpoint_url='http://localhost:8000') blog_engine = BloggingEngine(app, dyn_storage, file_upload=file_upload) login_manager = LoginManager(app) class User(UserMixin): def __init__(self, user_id): self.id = user_id def get_name(self): return "Paul Dirac" # typically the user's name @login_manager.user_loader @blog_engine.user_loader def load_user(user_id): return User(user_id)
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) db.init_app(app) migrate = Migrate() migrate.init_app(app, db=db) login_manager.session_protection = 'strong' login_manager.login_view = 'auth.login' login_manager.init_app(app) principal = Principal() principal.init_app(app) from app.models import User, Sentence, Quiz, Answer # Flask-Blogging database config with app.app_context(): storage = SQLAStorage(db=db) db.create_all() blog_engine = BloggingEngine() blog_engine.init_app(app, storage) misaka = Misaka(app=None, renderer=None, strikethrough=True, underline=True, tables=True, wrap=True) misaka.init_app(app) from wtforms.fields import HiddenField def is_hidden_field_filter(field): return isinstance(field, HiddenField) app.jinja_env.globals['bootstrap_is_hidden_field'] = \ is_hidden_field_filter # TODO: Move these auth handlers out of __init__.py @login_manager.user_loader # @blog_engine.user_loader def load_user(user_id): print "ID: ", user_id return User.query.get(int(user_id)) @login_manager.unauthorized_handler def handle_unauthorized(): if session.get('_id'): return redirect(url_for('auth.login')) else: login_user(User().save()) return redirect(request.url) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user if hasattr(current_user, "id"): identity.provides.add(UserNeed(current_user.id)) # Shortcut to the give admins "blogger" role. if hasattr(current_user, "is_admin"): if current_user.is_admin: identity.provides.add(RoleNeed("blogger")) from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') # Initialise flask-admin admin = Admin(app, template_mode='bootstrap3', index_view=AdminIndexView()) Post = storage.post_model # Add administrative views here admin.add_view(ModelView(User, db.session)) admin.add_view(ModelView(Post, db.session)) return app