def configurate_app(): app.secret_key = 'herebemysecretkey' app.config['SESSION_TYPE'] = 'filesystem' app.config['SQLALCHEMY_DATABASE_URI'] = sqlite_str() app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECURITY_REGISTERABLE'] = True app.config['SECRET_KEY'] = 'youcanaskhenryanythinganytime' app.config['SESSION_COOKIE_SECURE'] = False app.config['WTF_CSRF_ENABLED'] = False (security_ctx, user_datastore) = security.initialize(app) admin_ctx = admin.initialize(app) @security_ctx.context_processor def security_context_processor(): return dict(admin_base_template=admin_ctx.base_template, admin_view=admin_ctx.index_view, h=admin_helpers, get_url=url_for) db.init_app(app) app.app_context().push()
from utils import (slugify, form2object, object2form, login_required, admin_required, strip_tags, password_generator) from markdown2 import markdown from forms import LoginForm, HTMLPageForm, PageForm, RegisterForm, FileForm, bootswatch_themes import os, sys import admin app = Flask(__name__) app.config.from_pyfile('app.cfg') DB = TinyMongoClient().blog Bootstrap(app) ckeditor = CKEditor(app) admin.initialize(app, DB) dropzone = Dropzone() dropzone.init_app(app) ### FILE UPLOADS PARAMETERS # UPLOAD FOLDER will have to change based on your own needs/deployment scenario BASE_DIR = os.path.dirname(os.path.abspath(__file__)) UPLOAD_FOLDER = os.path.join(BASE_DIR, './uploads') app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) def create_user(username, password, email='', is_admin=False,
# local imports import forms import models import admin # my local utilities from utils import get_object_or_404 app = Flask(__name__) app.secret_key = 'PutYourSecretInHere' # set up logging file_handler = logging.FileHandler('app.log') app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) # set up admin admin = admin.initialize(app) # include bootstrap Bootstrap(app) # flask-login setup login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' @login_manager.user_loader def load_user(user_id): """returns user user based on user_id or None""" try: return models.User.get(models.User.id == user_id) except models.DoesNotExist:
# add some Bootstrap handling needed by WTForms Bootstrap(app) # set up logging log_handler = RotatingFileHandler('./log/info.log', maxBytes=2000, backupCount=1) log_format = logging.Formatter('%(asctime)s %(levelname)s %(message)s') log_handler.setLevel(logging.INFO) log_handler.setFormatter(log_format) app.logger.setLevel(logging.INFO) app.logger.addHandler(log_handler) # set up admin admin.initialize(app) def setup(): setattr(g, "brand", "FlaskPress") setattr(g, "brand_logo", "/static/fplogo/fp_logo_3.png") setattr(g, "brand_alt", "FlaskPress: a minimalist CMS based on Flask") # request handlers @app.before_request def before_request(): setup() g.db = models.DATABASE try: g.db.connect()
import admin import hooks admin.initialize() import filters import logging import oauth import requestlogger import sys assert hooks assert filters app = requestlogger.WSGILogger( admin.app, [logging.StreamHandler(sys.stdout)], requestlogger.ApacheFormatter() ) def github_oauth(): return oauth.start(oauth.github, admin.app.base_url + '/login/github/callback') def facebook_oauth(): return oauth.start(oauth.facebook, admin.app.base_url + '/login/facebook/callback') def twitter_oauth(): return oauth.start(oauth.twitter, admin.app.base_url + '/login/twitter/callback') github_oauth_callback = oauth.github_callback facebook_oauth_callback = oauth.facebook_callback