Esempio n. 1
0
    def _configure_paths(self, conf, app):
        try:
            package = conf['package'].__name__
        except (KeyError, AttributeError):
            package = None

        if package is not None:
            conf['package_name'] = conf['package'].__name__
        else:
            conf['package_name'] = None

        if package is None:
            # if we don't have a specified package (ES: we are in minimal mode)
            # we are unable to get paths from the package itself.
            paths = Bunch()
        else:
            root = os.path.dirname(os.path.abspath(conf['package'].__file__))
            paths = Bunch(
                root=root,
                controllers=os.path.join(root, 'controllers'),
                static_files=os.path.join(root, 'public'),
                templates=[os.path.join(root, 'templates')]
            )

        # If the user defined custom paths, then use them instead of the
        # default ones:
        paths.update(conf['paths'])

        # Ensure all paths are set, load default ones otherwise
        for key, val in self.DEFAULT_PATHS.items():
            paths.setdefault(key, val)

        conf['paths'] = paths
Esempio n. 2
0
    def _configure_paths(self, conf, app):
        try:
            package = conf['package'].__name__
        except (KeyError, AttributeError):
            package = None

        if package is not None:
            conf['package_name'] = conf['package'].__name__
        else:
            conf['package_name'] = None

        if package is None:
            # if we don't have a specified package (ES: we are in minimal mode)
            # we are unable to get paths from the package itself.
            paths = Bunch()
        else:
            root = os.path.dirname(os.path.abspath(conf['package'].__file__))
            paths = Bunch(root=root,
                          controllers=os.path.join(root, 'controllers'),
                          static_files=os.path.join(root, 'public'),
                          templates=[os.path.join(root, 'templates')])

        # If the user defined custom paths, then use them instead of the
        # default ones:
        paths.update(conf['paths'])

        # Ensure all paths are set, load default ones otherwise
        for key, val in self.DEFAULT_PATHS.items():
            paths.setdefault(key, val)

        conf['paths'] = paths
Esempio n. 3
0
 def setup_paths(self):
     root = os.path.dirname(os.path.abspath(self.package.__file__))
     # The default paths:
     paths = Bunch(root=root,
                   controllers=os.path.join(root, 'controllers'),
                   static_files=os.path.join(root, 'public'),
                   templates=[os.path.join(root, 'templates')])
     # If the user defined custom paths, then use them instead of the
     # default ones:
     paths.update(self.paths)
     self.paths = paths
 def setup_paths(self):
     root = os.path.dirname(os.path.abspath(self.package.__file__))
     # The default paths:
     paths = Bunch(root=root,
                  controllers=os.path.join(root, 'controllers'),
                  static_files=os.path.join(root, 'public'),
                  templates=[os.path.join(root, 'templates')])
     # If the user defined custom paths, then use them instead of the
     # default ones:
     paths.update(self.paths)
     self.paths = paths
Esempio n. 5
0
File: base.py Progetto: buxx/tracim
def _get_clean_sa_auth(config):
    """
    Return the original sa_auth parameter. Consider Original as it's content before first fill in configuration.
    :param config: tg2 app config
    :return: original sa_auth parameter
    """
    global _original_sa_auth

    if _original_sa_auth is None:
        _original_sa_auth = dict(config.get("sa_auth"))

    sa_auth = Bunch()
    sa_auth.update(_original_sa_auth)
    return sa_auth
Esempio n. 6
0
File: base.py Progetto: qyqx/tracim
def _get_clean_sa_auth(config):
    """
    Return the original sa_auth parameter. Consider Original as it's content before first fill in configuration.
    :param config: tg2 app config
    :return: original sa_auth parameter
    """
    global _original_sa_auth

    if _original_sa_auth is None:
        _original_sa_auth = dict(config.get('sa_auth'))

    sa_auth = Bunch()
    sa_auth.update(_original_sa_auth)
    return sa_auth
Esempio n. 7
0
def menu_variable_provider():
    menu_vars = Bunch(
        url_from_menu=url_from_menu,
        render_menu=render_menu,
        render_navbar=render_navbar,
        render_sidebar=render_sidebar,
    )

    try:
        from genshi import HTML
        menu_vars['HTML'] = HTML
    except ImportError:
        pass

    if app_variable_provider:
        menu_vars.update(app_variable_provider())

    return menu_vars
Esempio n. 8
0
def menu_variable_provider():
    menu_vars = Bunch (
        url_from_menu = url_from_menu,
        render_menu = render_menu,
        render_navbar = render_navbar,
        render_sidebar = render_sidebar,
    )
    
    try:
        from genshi import HTML
        menu_vars['HTML'] = HTML
    except ImportError:
        pass
    
    if app_variable_provider:
        menu_vars.update(app_variable_provider())

    return menu_vars
Esempio n. 9
0
def _get_tg_vars():
    """Create a Bunch of variables that should be available in all templates.

    These variables are:

    WARNING: This function should not be called from outside of the render()
    code.  Please consider this function as private.

    quote_plus
        the urllib quote_plus function
    url
        the turbogears.url function for creating flexible URLs
    identity
        the current visitor's identity information
    session
        the current beaker.session if the session_filter.on it set
        in the app.cfg configuration file. If it is not set then session
        will be None.
    locale
        the default locale
    inputs
        input values from a form
    errors
        validation errors
    request
        the WebOb Request Object
    config
        the app's config object
    auth_stack_enabled
        A boolean that determines if the auth stack is present in the environment
    predicates
        The :mod:`tg.predicates` module.

    """

    tgl = tg.request_local.context._current_obj()
    req = tgl.request
    conf = tgl.config
    tmpl_context = tgl.tmpl_context
    app_globals = tgl.app_globals
    translator = tgl.translator
    response = tgl.response
    session = tgl.session

    try:
        h = conf['package'].lib.helpers
    except (AttributeError, ImportError):
        h = Bunch()

    # TODO: Implement user_agent and other missing features.
    tg_vars = Bunch(
        config=tg.config,
        flash_obj=tg.flash,
        quote_plus=quote_plus,
        url=tg.url,
        # this will be None if no identity
        identity = req.environ.get('repoze.who.identity'),
        session = session,
        locale = req.plain_languages,
        errors = req.validation['errors'],
        inputs = req.validation['values'],
        request = req,
        auth_stack_enabled = 'repoze.who.plugins' in req.environ,
        predicates = predicates)

    root_vars = Bunch(
        c=tmpl_context,
        tmpl_context=tmpl_context,
        response=response,
        request=req,
        config=conf,
        app_globals=app_globals,
        g=app_globals,
        session=session,
        url=tg.url,
        helpers=h,
        h=h,
        tg=tg_vars,
        translator=translator,
        ungettext=tg.i18n.ungettext,
        _=tg.i18n.ugettext,
        N_=tg.i18n.gettext_noop)

    # Allow users to provide a callable that defines extra vars to be
    # added to the template namespace
    variable_provider = conf.get('variable_provider', None)
    if variable_provider:
        root_vars.update(variable_provider())
    return root_vars
Esempio n. 10
0
        tg=tg_vars,
        translator=translator,
        ungettext=tg.i18n.ungettext,
        _=tg.i18n.ugettext,
        N_=tg.i18n.gettext_noop,
    )

    econf = conf["pylons.environ_config"]
    if "beaker.session" in req.environ or ("session" in econf and econf["session"] in req.environ):
        root_vars["session"] = tg.session._current_obj()

    # Allow users to provide a callable that defines extra vars to be
    # added to the template namespace
    variable_provider = conf.get("variable_provider", None)
    if variable_provider:
        root_vars.update(variable_provider())
    return root_vars


# Monkey patch pylons_globals for cases when pylons.templating is used
# instead of tg.render to programmatically render templates.
import pylons

pylons.templating.pylons_globals = _get_tg_vars
# end monkeying around


def render(template_vars, template_engine=None, template_name=None, **kwargs):
    config = tg.config._current_obj()

    render_function = None
Esempio n. 11
0
def _get_tg_vars():
    """Create a Bunch of variables that should be available in all templates.

    These variables are:

    WARNING: This function should not be called from outside of the render()
    code.  Please consider this function as private.

    quote_plus
        the urllib quote_plus function
    url
        the turbogears.url function for creating flexible URLs
    identity
        the current visitor's identity information
    session
        the current beaker.session if the session_filter.on it set
        in the app.cfg configuration file. If it is not set then session
        will be None.
    locale
        the default locale
    inputs
        input values from a form
    errors
        validation errors
    request
        the WebOb Request Object
    config
        the app's config object
    auth_stack_enabled
        A boolean that determines if the auth stack is present in the environment
    predicates
        The :mod:`tg.predicates` module.

    """

    tgl = tg.request_local.context._current_obj()
    req = tgl.request
    conf = tgl.config
    tmpl_context = tgl.tmpl_context
    app_globals = tgl.app_globals
    translator = tgl.translator
    response = tgl.response
    session = tgl.session
    helpers = conf['helpers']

    try:
        validation = req.validation
    except AttributeError:
        validation = {}

    # TODO: Implement user_agent and other missing features.
    tg_vars = Bunch(
        config=tg.config,
        flash_obj=tg.flash,
        quote_plus=quote_plus,
        url=tg.url,
        # this will be None if no identity
        identity = req.environ.get('repoze.who.identity'),
        session = session,
        locale = req.plain_languages,
        errors = validation and validation.errors,
        inputs = validation and validation.values,
        request = req,
        auth_stack_enabled = 'repoze.who.plugins' in req.environ,
        predicates = predicates)

    root_vars = Bunch(
        c=tmpl_context,
        tmpl_context=tmpl_context,
        response=response,
        request=req,
        config=conf,
        app_globals=app_globals,
        g=app_globals,
        session=session,
        url=tg.url,
        helpers=helpers,
        h=helpers,
        tg=tg_vars,
        translator=translator,
        ungettext=tg.i18n.ungettext,
        _=tg.i18n.ugettext,
        N_=tg.i18n.gettext_noop)

    # Allow users to provide a callable that defines extra vars to be
    # added to the template namespace
    variable_provider = conf.get('variable_provider', None)
    if variable_provider:
        root_vars.update(variable_provider())
    return root_vars
Esempio n. 12
0
        tg=tg_vars,
        translator=translator,
        ungettext=tg.i18n.ungettext,
        _=tg.i18n.ugettext,
        N_=tg.i18n.gettext_noop)

    econf = conf['pylons.environ_config']
    if 'beaker.session' in req.environ or \
        ('session' in econf and econf['session'] in req.environ):
        root_vars['session'] = tg.session._current_obj()

    # Allow users to provide a callable that defines extra vars to be
    # added to the template namespace
    variable_provider = conf.get('variable_provider', None)
    if variable_provider:
        root_vars.update(variable_provider())
    return root_vars

# Monkey patch pylons_globals for cases when pylons.templating is used
# instead of tg.render to programmatically render templates.
import pylons
pylons.templating.pylons_globals = _get_tg_vars
# end monkeying around


def render(template_vars, template_engine=None, template_name=None, **kwargs):
    config = tg.config._current_obj()

    render_function = None
    if template_engine is not None:
        # the engine was defined in the @expose()