# -*- coding: utf-8 -*-
'''The app module, containing the app factory function.'''
from flask import Flask, render_template

from application.settings import ProdConfig
from application.assets import assets
from application.extensions import (
    bcrypt,
    cache,
    db,
    login_manager,
    migrate,
    debug_toolbar,
    asset_locator,
)
from application import (
    being_a_civil_servant,
    prejoining,
    public,
    user,
    jobs,
    professions,
    signup
)


def create_app(config_object=ProdConfig):
    '''An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/

    :param config_object: The configuration object to use.
    '''
    app = Flask(__name__)
    app.config.from_object(config_object)
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    return app


def register_extensions(app):
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    asset_locator.init_app(app)
    return None


def register_blueprints(app):
    app.register_blueprint(being_a_civil_servant.views.blueprint)
    app.register_blueprint(prejoining.views.blueprint)
    app.register_blueprint(public.views.blueprint)
    app.register_blueprint(user.views.blueprint)
    app.register_blueprint(jobs.views.blueprint)
    app.register_blueprint(professions.views.blueprint)
    app.register_blueprint(signup.views.blueprint)
    return None


def register_errorhandlers(app):
    def render_error(error):
        # If a HTTPException, pull the `code` attribute; default to 500
        error_code = getattr(error, 'code', 500)
        return render_template("{0}.html".format(error_code)), error_code
    for errcode in [401, 404, 500]:
        app.errorhandler(errcode)(render_error)
    return None

@@ -103,26 +103,9 @@
 lask
-, render_template
 %0A
+
 %0Afro
@@ -805,40 +805,8 @@
 pp)%0A
-    register_errorhandlers(app)%0A
     
@@ -1435,32 +1435,32 @@
 iews.blueprint)%0A
+
     app.register
@@ -1514,363 +1514,4 @@
 one%0A
-%0A%0Adef register_errorhandlers(app):%0A    def render_error(error):%0A        # If a HTTPException, pull the %60code%60 attribute; default to 500%0A        error_code = getattr(error, 'code', 500)%0A        return render_template(%22%7B0%7D.html%22.format(error_code)), error_code%0A    for errcode in %5B401, 404, 500%5D:%0A        app.errorhandler(errcode)(render_error)%0A    return None%0A

remove error handler