<commit_before># This file is part of Moksha.
# Copyright (C) 2008-2009  Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors: <NAME> <<EMAIL>>

import moksha
import pylons
import os

from tg import config, url
from tg import expose, flash, require, tmpl_context, redirect, validate
from tg.controllers import WSGIAppController
from tg.decorators import after_render

from repoze.what import predicates
from pkg_resources import resource_filename
#from widgetbrowser import WidgetBrowser
from pylons.i18n import ugettext as _, lazy_ugettext as l_

from moksha import _
from moksha.model import DBSession
from moksha.lib.base import BaseController
from moksha.lib.helpers import cache_rendered_data
from moksha.exc import ApplicationNotFound
from moksha.controllers.error import ErrorController
from moksha.controllers.apps import AppController
from moksha.controllers.widgets import WidgetController
from moksha.controllers.secure import SecureController

# So we can mount the WidgetBrowser as /docs
os.environ['TW_BROWSER_PREFIX'] = '/docs'

class RootController(BaseController):

    apps = AppController()
    widgets = WidgetController()
    error = ErrorController()
    moksha_admin = SecureController()

    # ToscaWidgets WidgetBrowser integration
    """
    docs = WSGIAppController(
                WidgetBrowser(
                    template_dirs=[
                        resource_filename('moksha','templates/widget_browser')],
                    docs_dir=config.get('docs_dir', 'docs'),
                    full_stack=False,
                    interactive=False))
    """

    #@after_render(cache_rendered_data)
    @expose('mako:moksha.templates.index')
    def index(self):
        tmpl_context.menu_widget = moksha.menus['default_menu']
        #tmpl_context.contextual_menu_widget = moksha.menus['contextual_menu']
        return dict(title='[ Moksha ]')

    @expose()
    def lookup(self, *remainder):
        """
        Moksha's default lookup method, called by the
        :class:`MokshaMiddleware`.  This currently dispatches to our
        WidgetBrowser when Moksha is being used as WSGI middleware in another
        application.
        """
        if pylons.request.path.startswith('/docs/'):
            return self.docs, remainder

    @expose('mako:moksha.templates.login')
    def login(self, came_from=None):
        """Start the user login."""
        if not came_from:
            came_from = url('/')
        login_counter = pylons.request.environ['repoze.who.logins']
        if login_counter > 0:
            flash(_('Wrong credentials'), 'warning')
        return dict(page='login', login_counter=str(login_counter),
                    came_from=came_from)
<commit_msg>Let moksha work without any menus loaded<commit_after># This file is part of Moksha.
# Copyright (C) 2008-2009  Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors: <NAME> <<EMAIL>>

import moksha
import pylons
import os

from tg import config, url
from tg import expose, flash, require, tmpl_context, redirect, validate
from tg.controllers import WSGIAppController
from tg.decorators import after_render

from repoze.what import predicates
from pkg_resources import resource_filename
#from widgetbrowser import WidgetBrowser
from pylons.i18n import ugettext as _, lazy_ugettext as l_

from moksha import _
from moksha.model import DBSession
from moksha.lib.base import BaseController
from moksha.lib.helpers import cache_rendered_data
from moksha.exc import ApplicationNotFound
from moksha.controllers.error import ErrorController
from moksha.controllers.apps import AppController
from moksha.controllers.widgets import WidgetController
from moksha.controllers.secure import SecureController

# So we can mount the WidgetBrowser as /docs
os.environ['TW_BROWSER_PREFIX'] = '/docs'

class RootController(BaseController):

    apps = AppController()
    widgets = WidgetController()
    error = ErrorController()
    moksha_admin = SecureController()

    # ToscaWidgets WidgetBrowser integration
    """
    docs = WSGIAppController(
                WidgetBrowser(
                    template_dirs=[
                        resource_filename('moksha','templates/widget_browser')],
                    docs_dir=config.get('docs_dir', 'docs'),
                    full_stack=False,
                    interactive=False))
    """

    #@after_render(cache_rendered_data)
    @expose('mako:moksha.templates.index')
    def index(self):
        if 'default_menu' in moksha.menus:
            tmpl_context.menu_widget = moksha.menus['default_menu']
        else:
            tmpl_context.menu_widget = ''
        #tmpl_context.contextual_menu_widget = moksha.menus['contextual_menu']
        return dict(title='[ Moksha ]')

    @expose()
    def lookup(self, *remainder):
        """
        Moksha's default lookup method, called by the
        :class:`MokshaMiddleware`.  This currently dispatches to our
        WidgetBrowser when Moksha is being used as WSGI middleware in another
        application.
        """
        if pylons.request.path.startswith('/docs/'):
            return self.docs, remainder

    @expose('mako:moksha.templates.login')
    def login(self, came_from=None):
        """Start the user login."""
        if not came_from:
            came_from = url('/')
        login_counter = pylons.request.environ['repoze.who.logins']
        if login_counter > 0:
            flash(_('Wrong credentials'), 'warning')
        return dict(page='login', login_counter=str(login_counter),
                    came_from=came_from)

{'fraction_non_alphanumeric': 0.0816955118803168, 'fraction_numerical': 0.0035200938691698444, 'mean_word_length': 3.29137822529893, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5739204', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1878, 'n_words': 618}