def setup_blueprints(app): """Configure blueprints.""" from pybossa.api import blueprint as api from pybossa.view.account import blueprint as account from pybossa.view.projects import blueprint as projects from pybossa.view.admin import blueprint as admin from pybossa.view.leaderboard import blueprint as leaderboard from pybossa.view.stats import blueprint as stats from pybossa.view.help import blueprint as helper from pybossa.view.home import blueprint as home from pybossa.view.uploads import blueprint as uploads from pybossa.view.amazon import blueprint as amazon blueprints = [{'handler': home, 'url_prefix': '/'}, {'handler': api, 'url_prefix': '/api'}, {'handler': account, 'url_prefix': '/account'}, {'handler': projects, 'url_prefix': '/project'}, {'handler': admin, 'url_prefix': '/admin'}, {'handler': leaderboard, 'url_prefix': '/leaderboard'}, {'handler': helper, 'url_prefix': '/help'}, {'handler': stats, 'url_prefix': '/stats'}, {'handler': uploads, 'url_prefix': '/uploads'}, {'handler': amazon, 'url_prefix': '/amazon'}, ] for bp in blueprints: app.register_blueprint(bp['handler'], url_prefix=bp['url_prefix']) from rq_dashboard import RQDashboard RQDashboard(app, url_prefix='/admin/rq', auth_handler=current_user, redis_conn=sentinel.master)
def CreateApp(configfile=None): from flask import Flask from flask.ext.appconfig import AppConfig from rq_dashboard import RQDashboard from flask_debug import Debug from flask.ext.rq import RQ result = Flask(__name__) AppConfig(result, default_settings="gir.config", configfile=configfile) result.config['RQ_DEFAULT_URL'] = result.config['REDIS_URL'] RQDashboard(result) Debug(result) RQ(result) return result
def setup_app(app): """Do general app setup so we can run from gunicorn or command line""" global HOST, PORT setup_db() app.config['SESSION_TYPE'] = 'redis' app.config['SECRET_KEY'] = '12345abcde' app.config['REDIS_URL'] = get_redis_url() # a DictStore will store everything in memory STORE = DictStore() # this will replace the app's session handling KVSessionExtension(STORE, APP) PORT = int(os.environ.get('PORT', 5000)) HOST = os.environ.get('HOST', 'localhost') LOGGER.info("Starting application on PORT=%d", PORT) # Bind to PORT if defined, otherwise default to 5000. app.debug = False #APP.testing = True app.secret_key = '12345abcde' RQDashboard(app)
import os from osp.common import config from osp.common.utils import partitions from flask import Flask, request from rq_dashboard import RQDashboard from pydoc import locate # RQ dashboard: app = Flask(__name__) RQDashboard(app) @app.route('/ping') def ping(): return ('pong', 200) @app.route('/queue', methods=['POST']) def queue(): """ Queue a work order. """ config.rq.enqueue( queue_page,
def setup_blueprints(app): """Configure blueprints.""" from pybossa.api import blueprint as api from pybossa.view.account import blueprint as account from pybossa.view.applications import blueprint as applications from pybossa.view.admin import blueprint as admin from pybossa.view.leaderboard import blueprint as leaderboard from pybossa.view.stats import blueprint as stats from pybossa.view.help import blueprint as helper from pybossa.view.home import blueprint as home from pybossa.view.uploads import blueprint as uploads blueprints = [ { 'handler': home, 'url_prefix': '/' }, { 'handler': api, 'url_prefix': '/api' }, { 'handler': account, 'url_prefix': '/account' }, { 'handler': applications, 'url_prefix': '/app' }, { 'handler': admin, 'url_prefix': '/admin' }, { 'handler': leaderboard, 'url_prefix': '/leaderboard' }, { 'handler': helper, 'url_prefix': '/help' }, { 'handler': stats, 'url_prefix': '/stats' }, { 'handler': uploads, 'url_prefix': '/uploads' }, ] for bp in blueprints: app.register_blueprint(bp['handler'], url_prefix=bp['url_prefix']) # The RQDashboard is actually registering a blueprint to the app, so this is # a propper place for it to be initialized from rq_dashboard import RQDashboard RQDashboard(app, url_prefix='/admin/rq', auth_handler=current_user, redis_conn=sentinel.master)
from server.security import check_basic_auth, setup_user_by_token from utils import Version, ValidationException requests.packages.urllib3.disable_warnings() logger = logging.getLogger('wigo.web') app = Flask(__name__, template_folder='server/templates') app.url_map.strict_slashes = False app.config.from_object(Configuration) app.session_interface = ApiSessionInterface() SSLify(app) Compress(app) RQDashboard(app, '/admin/rq', check_basic_auth) app.register_blueprint(api_blueprint) admin = Admin(app, name='Wigo', index_view=WigoAdminIndexView()) admin.add_view(GroupModelView(Group)) admin.add_view(UserModelView(User)) admin.add_view(EventModelView(Event)) admin.add_view(EventMessageView(EventMessage)) admin.add_view(MessageView(Message)) admin.add_view(ConfigView(Config)) wire_notifications_listeners() wire_uploads_listeners() wire_images_listeners() wire_predictions_listeners()
import tornado.ioloop import tornado.web from settings import * # connect to databases import connect_mongo import connect_redis # http://stackoverflow.com/questions/8143141/using-flask-and-tornado-together from flask import Flask from rq_dashboard import RQDashboard rq_dashboard_app = Flask(__name__) rq_dashboard_app.config['REDIS_URL'] = os.getenv('REDISTOGO_URL', 'redis://localhost:6379') RQDashboard(rq_dashboard_app, '/rq') tr = tornado.wsgi.WSGIContainer(rq_dashboard_app) # apps from apps.accounts.social import * from apps.accounts.handlers import * from apps.app.handlers import * logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(levelname)8s %(name)s - %(message)s', datefmt='%H:%M:%S') TORNADO_ROUTES = [ (r'/?', HomeHandler), (r'/auth/facebook/?', FacebookLoginHandler),
app = Flask(__name__) app.config['DEBUG'] = False if os.getenv('IS_HEROKU', False) else True ## Set the following to True to avoid auth issues. # app.config['TESTING'] = True app.config[ 'SECRET_KEY'] = '~\x88\xb1\xfa\xb0\xe5\xaf\x82\x18\xc3\xfd\xff\xff\x80=\x9e\x90\x976\xb7\xb3\xbbN\x84' app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv( 'DATABASE_URL', 'postgres://%s' % 'apiski:@localhost/apiski') app.config['REDIS_URL'] = os.getenv('REDIS_URL', 'redis://localhost:6379') sslify = SSLify(app, skips=[]) # Old line #sslify = SSLify(app, skips=['static']) # Enable rq-dashboard import queues rqd = RQDashboard(app=app) # Step 2: initialize extensions. dbnew.init_app(app) db = dbnew db.app = app migrate = Migrate(app, db) api_manager = APIManager(app, flask_sqlalchemy_db=db) script_manager = ScriptManager(app) script_manager.add_command('db', MigrateCommand) login_manager = LoginManager() login_manager.login_view = '/login' login_manager.setup_app(app) # Step 5: this is required for Flask-Login.
from social_relay import app from social_relay.utils.queues import public_queue from social_relay.utils.statistics import get_subscriber_stats, get_count_stats, log_receive_statistics # RQ DASHBOARD if app.config.get("RQ_DASHBOARD"): # Snippet from https://github.com/nvie/rq-dashboard/issues/75#issuecomment-90843823 # Prepare the authentication for the RQ dashboard def _basic_http_auth(): auth = request.authorization return auth and auth.password == app.config.get("RQ_DASHBOARD_PASSWORD") and \ auth.username == app.config.get("RQ_DASHBOARD_USERNAME") # And we register it RQDashboard(app, auth_handler=_basic_http_auth) # NOTE: RQ Dashboard is registered as a blueprint and thus we can setup a Flask error handler for our case. # When the configured RQ Dashboard auth_handler returns False, a 401 HTTPException is thrown out, # so we can intercept it. Thus, we setup an error handler for the rq_dashboard blueprint. def _auth_exception_handler(error): return '', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'} app.error_handler_spec.setdefault('rq_dashboard', {})[401] = _auth_exception_handler # Bower Bower(app) # Main routes
#!/usr/bin/env python # -*- coding: utf-8 -*- from flask import Flask, request from flask.ext import restful from rq_dashboard import RQDashboard from redis import Redis from rq import Queue from rq.job import Job from wordcount import count_words_at_url import logging import json # set the project root directory as the static folder, you can set others. flaskapp = Flask(__name__, static_url_path='') api = restful.Api(flaskapp) RQDashboard(flaskapp) conn = Redis() queue = Queue(connection=conn) @flaskapp.route('/') def index(): return flaskapp.send_static_file('index.html') @flaskapp.route('/testapi/hello') def testapi_hello(): return '{"hello":"world"}' @flaskapp.route('/testapi/wcount')
# from flask_login import LoginManager # login_manager = LoginManager() from flask_migrate import Migrate migrate = Migrate() from flask_cache import Cache cache = Cache() from flask_debugtoolbar import DebugToolbarExtension debug_toolbar = DebugToolbarExtension() from flask_bootstrap import Bootstrap bootstrap = Bootstrap() from rq_dashboard import RQDashboard from recruit_app.user.admin import check_if_admin rqDashboard = RQDashboard(auth_handler=check_if_admin) from flask_admin import Admin admin = Admin() from flask_mail import Mail mail = Mail() from flask_rq import RQ rq = RQ()
from flask import Flask from rq_dashboard import RQDashboard import os app = Flask(__name__) if os.getenv('RQ_DASHBOARD_SETTINGS'): app.config.from_envvar('RQ_DASHBOARD_SETTINGS') RQDashboard(app, os.getenv('APPLICATION_ROOT', ''))
from flask import Flask from rq_dashboard import RQDashboard import os app = Flask(__name__) if os.getenv('RQ_DASHBOARD_SETTINGS'): app.config.from_envvar('RQ_DASHBOARD_SETTINGS') RQDashboard(app, '')
from flask import Flask from rq_dashboard import RQDashboard import os app = Flask(__name__) if os.getenv('RQ_DASHBOARD_SETTINGS'): app.config.from_envvar('RQ_DASHBOARD_SETTINGS') RQDashboard(app, app.config.get('URL_PREFIX', ''))