<commit_before># -*- coding: utf-8 -*-
"""Main Controller"""

from datetime import datetime
from tg import expose, flash, url, lurl, request, redirect, require
from tg.i18n import ugettext as _, lazy_ugettext as l_
from repoze.what.predicates import Any, not_anonymous
from skylines import model
from skylines.model import DBSession
from tgext.admin.tgadminconfig import TGAdminConfig
from tgext.admin.controller import AdminController

from skylines.lib.base import BaseController
from skylines.controllers.error import ErrorController
from skylines.controllers.users import UsersController
from skylines.controllers.clubs import ClubsController
from skylines.controllers.flights import FlightsController
from skylines.controllers.ranking import RankingController
from skylines.controllers.tracking import TrackingController
from skylines.controllers.static import StaticResourceController
from skylines.controllers.statistics import StatisticsController

__all__ = ['RootController']


class RootController(BaseController):
    """
    The root controller for the SkyLines application.

    All the other controllers and WSGI applications should be mounted on this
    controller. For example::

        panel = ControlPanelController()
        another_app = AnotherWSGIApplication()

    Keep in mind that WSGI applications shouldn't be mounted directly: They
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.

    """
    admin = AdminController(model, DBSession, config_type = TGAdminConfig)

    error = ErrorController()
    users = UsersController()
    clubs = ClubsController()
    flights = FlightsController()
    ranking = RankingController()
    tracking = TrackingController()
    static = StaticResourceController()
    statistics = StatisticsController()

    @expose()
    def index(self):
        """Handle the front-page."""
        redirect('/flights/today')

    @expose('skylines.templates.about')
    def about(self):
        """Handle the 'about' page."""
        return dict()

    @expose('skylines.templates.login')
    def login(self, came_from = None):
        """Start the user login."""
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        return dict(page = 'login', came_from = came_from)

    @expose()
    def post_login(self, came_from = None):
        """
        Redirect the user to the initially requested page on successful
        authentication or redirect her back to the login page if login failed.

        """
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        if not request.identity:
            flash(_('Sorry, username or password are wrong. Please try again or register.'), 'warning')
        else:
            request.identity['user'].login_ip = request.remote_addr
            request.identity['user'].login_time = datetime.now()

            userid = request.identity['repoze.who.userid']
            flash(_('You are now logged in. Welcome back, %s!') % userid)

        redirect(came_from)

    @expose()
    def post_logout(self, came_from = None):
        """
        Redirect the user to the initially requested page on logout and say
        goodbye as well.

        """
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        flash(_('You are now logged out. We hope to see you back soon!'))
        redirect(came_from)

    @expose()
    @require(Any(not_anonymous(), msg='Please login to see this page!'))
    def settings(self):
        redirect('/users/' + str(request.identity['user'].user_id))<commit_msg>controllers.root: add comment<commit_after># -*- coding: utf-8 -*-
"""Main Controller"""

from datetime import datetime
from tg import expose, flash, url, lurl, request, redirect, require
from tg.i18n import ugettext as _, lazy_ugettext as l_
from repoze.what.predicates import Any, not_anonymous
from skylines import model
from skylines.model import DBSession
from tgext.admin.tgadminconfig import TGAdminConfig
from tgext.admin.controller import AdminController

from skylines.lib.base import BaseController
from skylines.controllers.error import ErrorController
from skylines.controllers.users import UsersController
from skylines.controllers.clubs import ClubsController
from skylines.controllers.flights import FlightsController
from skylines.controllers.ranking import RankingController
from skylines.controllers.tracking import TrackingController
from skylines.controllers.static import StaticResourceController
from skylines.controllers.statistics import StatisticsController

__all__ = ['RootController']


class RootController(BaseController):
    """
    The root controller for the SkyLines application.

    All the other controllers and WSGI applications should be mounted on this
    controller. For example::

        panel = ControlPanelController()
        another_app = AnotherWSGIApplication()

    Keep in mind that WSGI applications shouldn't be mounted directly: They
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.

    """
    admin = AdminController(model, DBSession, config_type = TGAdminConfig)

    error = ErrorController()
    users = UsersController()
    clubs = ClubsController()
    flights = FlightsController()
    ranking = RankingController()
    tracking = TrackingController()
    static = StaticResourceController()
    statistics = StatisticsController()

    @expose()
    def index(self):
        """Handle the front-page."""
        redirect('/flights/today')

    @expose('skylines.templates.about')
    def about(self):
        """Handle the 'about' page."""
        return dict()

    @expose('skylines.templates.login')
    def login(self, came_from = None):
        """Start the user login."""
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        return dict(page = 'login', came_from = came_from)

    @expose()
    def post_login(self, came_from = None):
        """
        Redirect the user to the initially requested page on successful
        authentication or redirect her back to the login page if login failed.

        """
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        if not request.identity:
            flash(_('Sorry, username or password are wrong. Please try again or register.'), 'warning')
        else:
            request.identity['user'].login_ip = request.remote_addr
            request.identity['user'].login_time = datetime.now()

            userid = request.identity['repoze.who.userid']
            flash(_('You are now logged in. Welcome back, %s!') % userid)

        redirect(came_from)

    @expose()
    def post_logout(self, came_from = None):
        """
        Redirect the user to the initially requested page on logout and say
        goodbye as well.

        """
        if not came_from:
            if request.referrer:
                came_from = request.referrer
            else:
                came_from = lurl('/')

        flash(_('You are now logged out. We hope to see you back soon!'))
        redirect(came_from)

    @expose()
    @require(Any(not_anonymous(), msg='Please login to see this page!'))
    def settings(self):
        """Only for compatibility with old bookmarks."""
        redirect('/users/' + str(request.identity['user'].user_id))
{'fraction_non_alphanumeric': 0.08999613750482811, 'fraction_numerical': 0.000772499034376207, 'mean_word_length': 2.866600298656048, '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': '5368365', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2017, 'n_words': 639}