Beispiel #1
0
    def create_app(self, config=None):
        app = Flask('signac-dashboard')
        app.config.update(dict(SECRET_KEY=b'NlHFEbC89JkfGLC3Lpk8'))

        # Load the provided config
        app.config.update(config or {})

        # Enable profiling
        if app.config.get('PROFILE'):
            logger.warning("Application profiling is enabled.")
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

        # Set up default signac-dashboard static and template paths
        signac_dashboard_path = os.path.dirname(__file__)
        app.static_folder = signac_dashboard_path + '/static'
        app.template_folder = signac_dashboard_path + '/templates'

        # Set up custom template paths
        # The paths in DASHBOARD_DIRS give the preferred order of template
        # loading
        loader_list = []
        for dashpath in list(app.config.get('DASHBOARD_PATHS', [])):
            logger.warning("Adding '{}' to dashboard paths.".format(dashpath))
            loader_list.append(jinja2.FileSystemLoader(dashpath +
                                                       '/templates'))

        # The default loader goes last and is overridden by any custom paths
        loader_list.append(app.jinja_loader)

        app.jinja_loader = jinja2.ChoiceLoader(loader_list)

        # Add pagination support from http://flask.pocoo.org/snippets/44/
        def url_for_other_page(page):
            args = request.args.copy()
            args['page'] = page
            return url_for(request.endpoint, **args)

        app.jinja_env.globals['url_for_other_page'] = url_for_other_page

        turbolinks(app)

        return app
Beispiel #2
0
    def _create_app(self, config={}):
        """Creates a Flask application.

        :param config: Dictionary of configuration parameters.
        """
        app = Flask('citytours')
        app.config.update({
            'SECRET_KEY': os.urandom(24),
            'SEND_FILE_MAX_AGE_DEFAULT': 300,  # Cache control for static files
        })

        # Load the provided config
        app.config.update(config)

        # Enable profiling
        if app.config.get('PROFILE'):
            logger.warning("Application profiling is enabled.")
            from werkzeug.contrib.profiler import ProfilerMiddleware
            app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10])

        # Set up default static and template paths
        package_path = os.path.dirname(__file__)
        app.static_folder = package_path + '/static'
        app.template_folder = package_path + '/templates'

        # Set up custom template paths
        # The paths in DASHBOARD_PATHS give the preferred order of template
        # loading
        loader_list = []
        for dashpath in list(app.config.get('DASHBOARD_PATHS', [])):
            logger.warning("Adding '{}' to CityTour paths.".format(dashpath))
            loader_list.append(jinja2.FileSystemLoader(dashpath +
                                                       '/templates'))

        # The default loader goes last and is overridden by any custom paths
        loader_list.append(app.jinja_loader)

        app.jinja_loader = jinja2.ChoiceLoader(loader_list)

        turbolinks(app)

        return app
from flask import Flask, redirect, request
from flask_turbolinks import turbolinks


app = Flask(__name__)
app.secret_key = 'secret'

turbolinks(app)


@app.route('/')
def home():
    return request.referer or ''


@app.route('/page')
def page():
    return 'page'


@app.route('/redirect')
def in_redirect():
    return redirect('/page')


@app.route('/x-redirect')
def x_redirect():
    return redirect('http://lepture.com')


client = app.test_client()
Beispiel #4
0
from flask import Flask, render_template, redirect
from flask_turbolinks import turbolinks


app = Flask(__name__)
app.secret_key = 'secret'

turbolinks(app)


@app.route('/')
def home():
    return render_template('home.html')


@app.route('/page')
def page():
    return render_template('page.html')


@app.route('/redirect')
def in_redirect():
    return redirect('/page')


@app.route('/x-redirect')
def x_redirect():
    return redirect('http://lepture.com')


if __name__ == '__main__':
Beispiel #5
0
import wtforms.validators as validators

import re
# this is valid for the trost server
sys.path.append("/opt/manatee/2.107.1/lib/python2.7/site-packages/")
import manatee

app = Flask("marlin")

# CONFIG
app.config.update(
    SECRET_KEY="a random string",
    DEFAULT_CORPUS="syn2015",
    CACHE_DIR=os.path.abspath(".cache"),
    MANATEE_REGISTRY="/home/manatee/registry")
app = turbolinks(app)
os.environ["MANATEE_REGISTRY"] = app.config["MANATEE_REGISTRY"]


def find_corpora(registry):
    corpora = set()
    for dirpath, _, filenames in os.walk(registry):
        for name in filenames:
            with open(os.path.join(dirpath, name)) as fh:
                try:
                    line = fh.readline().strip()
                    prop, _ = re.split(r"\s+", line, 1)
                # split unsuccessful
                except ValueError:
                    next
            if prop == "NAME":
Beispiel #6
0
def create_current_app(config_class=Config):
    app = Flask(__name__)
    if config_class:
        app.config.from_object(config_class)
    app.redis = Redis.from_url(Config.redis_server)
    app.task_queue = rq.Queue('flaskgram-tasks', connection=app.redis)
    cache.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    mail.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    babel.init_app(app)
    share.init_app(app)
    bcrypt.init_app(app)
    discussion.init_app(app)
    turbolinks(app)

    app.elasticsearch = Elasticsearch(
        connect_to_bonsai_search()) if Config.ELASTIC_SEARCH_URL else None

    from srcode.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from srcode.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')

    from srcode.user import bp as user_bp
    app.register_blueprint(user_bp)

    from srcode.community import community as community_bp
    app.register_blueprint(community_bp)

    from srcode.auth.oauth import google_blueprint as google_bp
    app.register_blueprint(google_bp)

    from srcode.auth.oauth import facebook_blueprint as facebook_bp
    app.register_blueprint(facebook_bp)

    from srcode.auth.oauth import github_blueprint as github_bp
    app.register_blueprint(github_bp)

    from srcode.auth.oauth import twitter_blueprint as twitter_bp
    app.register_blueprint(twitter_bp)
    with app.app_context():
        db.create_all()
        if db.engine.url.drivername == 'sqlite':
            migrate.init_app(app, db, render_as_batch=True)
        else:
            migrate.init_app(app, db)

    if not app.debug and not app.testing:
        if not os.path.exists('logs'):
            os.mkdir('logs')
        file_handler = RotatingFileHandler('logs/srcode.log',
                                           maxBytes=10240,
                                           backupCount=10)
        file_handler.setFormatter(
            logging.Formatter(
                '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
            ))
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)
        app.logger.setLevel(logging.INFO)
        app.logger.info('Flaskgram startup')
    return app