Exemplo n.º 1
0
def get_translations(locale=None):
    """Get the translation for a locale."""
    if not locale:
        locale = local('locale')
    translations = _translations.get(str(locale))
    if translations is not None:
        return translations
    application = local('application')
    rv = Translations.load(os.path.join(application.HERE_PATH,
                                        application.cache.appname,
                                        "i18n"), [locale])
    _translations[str(locale)] = rv
    return rv
Exemplo n.º 2
0
from werkzeug.routing import Rule
from functools import wraps

from rdrei.core.local import local

import time, logging, inspect

log = logging.getLogger(__name__)
application = local('application')
url_map = application.import_from_app("urls", "url_map")

def expose(rule, **kw):
    def decorate(f):
        kw['endpoint'] = f.__module__.split('.')[-1]+"/"+f.__name__
        url_map.add(Rule(rule, **kw))
        return f
    return decorate

def beaker_cache(key="cache_default", expire="never", type=None,
                 query_args=False,
                 cache_headers=('content-type', 'content-length'),
                 invalidate_on_startup=False, **b_kwargs):
    """Cache decorator utilizing Beaker. Caches action or other
    function that returns a pickle-able object as a result.

    Optional arguments:

    ``key``
        None - No variable key, uses function name as key
        "cache_default" - Uses all function arguments as the key
        string - Use kwargs[key] as key