Example #1
0
def create_app(environment_name):
    """Create the actual Flask application."""
    app = Flask(__name__)

    load_config(app, environment_name)

    # Throw an exception when an undefined name is referenced in a template.
    app.jinja_env.undefined = jinja2.StrictUndefined

    # Set the locale.
    set_locale(app.config["LOCALE"])  # Fail if not configured.

    # Add the time zone to the configuration.
    app.config["TIMEZONE"] = TIMEZONE

    # Disable Flask-SQLAlchemy's tracking of object modifications.
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

    # Initialize database.
    db.init_app(app)

    redis.init_app(app)

    email.init_app(app)

    config.init_app(app)

    register_blueprints(app)

    dateformat.register_template_filters(app)
    money.register_template_filters(app)

    app.add_url_rule("/content/<path:filename>", endpoint="content_file", methods=["GET"], build_only=True)

    app.add_url_rule("/content/brand/<path:filename>", endpoint="brand_file", build_only=True)

    return app
Example #2
0
            else:
                raise GitHubError(response)
        return result
    else:
        return response


GitHub.request = patched_github_request

app = Flask(__name__)
app.secret_key = "secret"
app.config["ORGANISATION"] = "Kozea"
app.config["GITHUB_CLIENT_ID"] = "4891551b9540ce8c4280"
app.config["GITHUB_CLIENT_SECRET"] = "bcfee82e06c41d22cd324b33a86c1e82a372c403"
app.config.from_envvar("GIBOLT_SETTINGS", silent=True)
app.config["TIMEZONE"] = "Europe/Paris"


@app.template_filter("sort_by_len")
def sort_by_len(values, reverse=False):
    """Sort the ``values`` list by the length of its second item.```"""
    return sorted(values, key=lambda item: len(item[1]), reverse=reverse)


@app.template_filter("format_date")
def format_date_filter(isodate, dateformat):
    """Transform an ISO-date to a string following ``dateformat``."""
    numbers = [int(number) for number in isodate.split("-")]
    while len(numbers) < 3:
        numbers.append(1)
    return date(*numbers).strftime(dateformat)