<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2014 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
"""
    web
    ~~~~~~~~~~~~~~

    This package contains the web interface based on flask

    :copyright: (c) 2012 by AG DSN.
"""

from flask import Flask, redirect, url_for, request, flash
from flask.ext.babel import Babel
from blueprints import finance, infrastructure, properties, user, dormitories, login
from web.form import widgets
import template_filters
import template_tests

from pycroft.model import session
from web.blueprints.login import login_manager
from flask.ext.login import current_user, current_app
from web.templates import page_resources


def make_app(connection_string):
    """  Create and configure the main? Flask app object

    :return: The fully configured app object
    """
    session.init_session(connection_string)

    app = Flask(__name__)

    #initialization code
    app.secret_key = \
        r"eiNohfaefaig5Iek6oshai0eijuph4ohla6Eo1vi5bahnaeh3Bah7ohy1einuaxu"

    login_manager.init_app(app)

    app.register_blueprint(user.bp, url_prefix="/user")
    app.register_blueprint(dormitories.bp, url_prefix="/dormitories")
    app.register_blueprint(infrastructure.bp, url_prefix="/infrastructure")
    app.register_blueprint(properties.bp, url_prefix="/properties")
    app.register_blueprint(finance.bp, url_prefix="/finance")
    app.register_blueprint(login.bp)

    template_filters.register_filters(app)
    template_tests.register_checks(app)

    app.config["BABEL_DEFAULT_LOCALE"] = "de"
    app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/Berlin"
    babel = Babel(app)

    page_resources.init_app(app)

    user.nav.register_on(app)
    finance.nav.register_on(app)
    dormitories.nav.register_on(app)
    infrastructure.nav.register_on(app)
    properties.nav.register_on(app)


    @app.errorhandler(401)
    @app.errorhandler(403)
    @app.errorhandler(404)
    @app.errorhandler(500)
    def errorpage(e):
        """Handle errors according to their error code

        :param e: The error from the errorhandler
        """
        if e.code in (401, 403):
            flash(u"Nicht genügend Rechte um die Seite zu sehen!", "error")
        elif e.code in (404,):
            flash(u"Seite wurde nicht gefunden!", "error")
        elif e.code in (500,):
            flash(e, "error")
        else:
            flash(u"Fehler!", "error")

        if request.referrer:
            return redirect(request.referrer)
        return redirect("/")

    @app.route('/')
    def redirect_to_index():
        return redirect(url_for('user.overview'))

    @app.teardown_request
    def shutdown_session(exception=None):
        session.session.remove()

    @app.before_request
    def require_login():
        """Request a login for every page
        except the login blueprint and the static folder.

        Blueprint "None" is needed for "/static/*" GET requests.
        """
        if current_user.is_anonymous() and request.blueprint not in ("login", None):
            return current_app.login_manager.unauthorized()

    return app
<commit_msg>More defaults restored<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2014 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.
"""
    web
    ~~~~~~~~~~~~~~

    This package contains the web interface based on flask

    :copyright: (c) 2012 by AG DSN.
"""

from flask import Flask, redirect, url_for, request, flash
from flask.ext.babel import Babel
from blueprints import finance, infrastructure, properties, user, dormitories, login
from web.form import widgets
import template_filters
import template_tests

from pycroft.model import session
from web.blueprints.login import login_manager
from flask.ext.login import current_user, current_app
from web.templates import page_resources


def make_app(connection_string=None):
    """  Create and configure the main? Flask app object

    :return: The fully configured app object
    """
    session.init_session(connection_string)

    app = Flask(__name__)

    #initialization code
    app.secret_key = \
        r"eiNohfaefaig5Iek6oshai0eijuph4ohla6Eo1vi5bahnaeh3Bah7ohy1einuaxu"

    login_manager.init_app(app)

    app.register_blueprint(user.bp, url_prefix="/user")
    app.register_blueprint(dormitories.bp, url_prefix="/dormitories")
    app.register_blueprint(infrastructure.bp, url_prefix="/infrastructure")
    app.register_blueprint(properties.bp, url_prefix="/properties")
    app.register_blueprint(finance.bp, url_prefix="/finance")
    app.register_blueprint(login.bp)

    template_filters.register_filters(app)
    template_tests.register_checks(app)

    app.config["BABEL_DEFAULT_LOCALE"] = "de"
    app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/Berlin"
    babel = Babel(app)

    page_resources.init_app(app)

    user.nav.register_on(app)
    finance.nav.register_on(app)
    dormitories.nav.register_on(app)
    infrastructure.nav.register_on(app)
    properties.nav.register_on(app)


    @app.errorhandler(401)
    @app.errorhandler(403)
    @app.errorhandler(404)
    @app.errorhandler(500)
    def errorpage(e):
        """Handle errors according to their error code

        :param e: The error from the errorhandler
        """
        if e.code in (401, 403):
            flash(u"Nicht genügend Rechte um die Seite zu sehen!", "error")
        elif e.code in (404,):
            flash(u"Seite wurde nicht gefunden!", "error")
        elif e.code in (500,):
            flash(e, "error")
        else:
            flash(u"Fehler!", "error")

        if request.referrer:
            return redirect(request.referrer)
        return redirect("/")

    @app.route('/')
    def redirect_to_index():
        return redirect(url_for('user.overview'))

    @app.teardown_request
    def shutdown_session(exception=None):
        session.session.remove()

    @app.before_request
    def require_login():
        """Request a login for every page
        except the login blueprint and the static folder.

        Blueprint "None" is needed for "/static/*" GET requests.
        """
        if current_user.is_anonymous() and request.blueprint not in ("login", None):
            return current_app.login_manager.unauthorized()

    return app

{'fraction_non_alphanumeric': 0.10300890389929383, 'fraction_numerical': 0.01381639545594105, 'mean_word_length': 3.334664005322688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2078669', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1952, 'n_words': 508}