Beispiel #1
0
def create_app(instance_path=None):
    app = flask.Flask(__name__,
                      instance_path=instance_path,
                      instance_relative_config=True)
    app.config.update(default_config)
    app.config.from_pyfile("settings.py", silent=True)
    database.initialize_app(app)
    auth.initialize_app(app)
    participant.initialize_app(app)
    meeting.initialize_app(app)
    printouts.initialize_app(app)
    charts.initialize_app(app)
    return app
Beispiel #2
0
def create_app(instance_path=None, config={}):
    app = flask.Flask(__name__,
                      instance_path=instance_path,
                      instance_relative_config=True)
    app.config.update(default_config)
    app.config.from_pyfile("settings.py", silent=True)
    app.config.update(config)

    sentry.init_app(app)
    import logging
    from raven.conf import setup_logging
    from raven.handlers.logging import SentryHandler
    sentry_handler = SentryHandler(sentry.client)
    sentry_handler.setLevel(logging.WARN)
    setup_logging(sentry_handler)

    if app.config['DEBUG']:
        app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
            "/static/photos": app.config['UPLOADED_PHOTOS_DEST'],
            "/static/files": app.config['UPLOADED_FILES_DEST'],
            "/static/badges": app.config['BADGES_PATH'],
            "/static/printouts": app.config['PRINTOUTS_PATH'],
            "/static/backgrounds": app.config['UPLOADED_BACKGROUNDS_DEST'],
        })

    assets = Environment(app)
    js = Bundle(*BUNDLE_JS, filters='jsmin', output='output/packed.js')
    css = Bundle(*BUNDLE_CSS, filters='cssmin', output='output/packed.css')
    assets.register('packed_js', js)
    assets.register('packed_css', css)

    database.initialize_app(app)
    auth.initialize_app(app)
    participant.initialize_app(app)
    meeting.initialize_app(app)
    printouts.initialize_app(app)
    country.initialize_app(app)
    resolution.initialize_app(app)
    staff.initialize_app(app)
    categories.initialize_app(app)
    update_local_database.initialize_app(app)
    media_participant.initialize_app(app)
    settings.initialize_app(app)

    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.filters['sag'] = sort_and_group
    app.jinja_env.filters['group_categories_under_parent'] = group_categories_under_parent
    app.jinja_env.filters['count'] = count
    app.jinja_env.filters['sort_by_criteria'] = sort_by_criteria
    app.jinja_env.filters['normalize'] = normalize
    app.jinja_env.filters['registered_date'] = registered_date
    app.jinja_env.filters['dtformat'] = dtformat
    app.jinja_env.filters['string_to_date'] = string_to_date
    app.jinja_env.filters['with_credentials'] = with_credentials
    app.jinja_env.filters['representing'] = representing
    app.jinja_env.filters['decode'] = decode
    app.jinja_env.filters['full_date'] = full_date
    app.jinja_env.filters['groupbyparty'] = groupbyparty
    app.jinja_env.filters['sortvisitorlast'] = sortvisitorlast

    app.context_processor(inject_static_path)
    app.context_processor(css_injector)
    app.context_processor(inject_user)
    app.context_processor(inject_config)

    babel = Babel(app)

    @app.before_request
    def load_user():
        email = flask.session.get('logged_in_email')
        try:
            user = Staff.select().where(data__contains={'email': email}).get()
        except Staff.DoesNotExist:
            user = None
        flask.g.user = user

    @babel.localeselector
    def get_locale():
        return getattr(flask.g, 'locale', 'en')

    @app.route('/ping')
    def ping():
        list(database.find('meeting'))
        return "cites is ok"

    @app.route('/crashme')
    def crashme():
        raise ValueError("Crashing, as requested.")

    return app