Exemple #1
0
def render(path, **kwargs):
    """Render a template with jinja2

    Args:
      path (str): the path to the template; should be of the form
      "dir/filename.html"

    """

    env = Environment(loader=FileSystemLoader(template_rootdir),
                      extensions=[formencode_jinja2.formfill,
                                  'jinja2.ext.i18n'])
    env.install_gettext_translations(i18n)

    template = env.get_template(path)

    static_cache_version = config.get("openspending.static_cache_version", "")
    if static_cache_version != "":
        static_cache_version = "?" + static_cache_version

    params = {
        "script_root": h.script_root(),
        "script_boot": h.script_tag('prod/boot'),
        "bootstrap_css": h.static('style/bootstrap.css'),
        "style_css": h.static('style/style.css'),
        "number_symbols_group": c.locale.number_symbols.get('group'),
        "number_symbols_decimal": c.locale.number_symbols.get('decimal'),
        "site_title": app_globals.site_title,
        "static": config.get("openspending.static_path", "/static/"),
        "static_cache_version": static_cache_version,
        "messages": list(h._flash.pop_messages()),
        "languages": languages(c.detected_l10n_languages, c.language),
        "section_active": section_active(c.content_section),
        "account": c.account is not None,
        "h": h,
        "c": c,
        "g": app_globals,
        "can": can,
        "show_rss": hasattr(c, 'show_rss') and c.show_rss or None,
    }
    params.update(kwargs)
    if 'form_fill' in params:
        if params['form_fill'] is not None and len(params['form_fill']) > 0:
            params['form_fill'] = dict(params['form_fill'])
        else:
            params['form_fill'] = {}

    return template.render(params)
Exemple #2
0
def render(path, **kwargs):
    """Render a template with jinja2

    Args:
      path (str): the path to the template; should be of the form
      "dir/filename.html"

    """

    env = Environment(
        loader=FileSystemLoader(template_rootdir),
        extensions=[formencode_jinja2.formfill, 'jinja2.ext.i18n'])
    env.install_gettext_translations(i18n)

    template = env.get_template(path)

    static_cache_version = config.get("openspending.static_cache_version", "")
    if static_cache_version != "":
        static_cache_version = "?" + static_cache_version

    params = {
        "script_root": h.script_root(),
        "script_boot": h.script_tag('prod/boot'),
        "bootstrap_css": h.static('style/bootstrap.css'),
        "style_css": h.static('style/style.css'),
        "number_symbols_group": c.locale.number_symbols.get('group'),
        "number_symbols_decimal": c.locale.number_symbols.get('decimal'),
        "site_title": app_globals.site_title,
        "static": config.get("openspending.static_path", "/static/"),
        "static_cache_version": static_cache_version,
        "messages": list(h._flash.pop_messages()),
        "languages": languages(c.detected_l10n_languages, c.language),
        "section_active": section_active(c.content_section),
        "account": c.account is not None,
        "h": h,
        "c": c,
        "g": app_globals,
        "can": can,
        "show_rss": hasattr(c, 'show_rss') and c.show_rss or None,
    }
    params.update(kwargs)
    if 'form_fill' in params:
        if params['form_fill'] is not None and len(params['form_fill']) > 0:
            params['form_fill'] = dict(params['form_fill'])
        else:
            params['form_fill'] = {}

    return template.render(params)
Exemple #3
0
def get_widget(name, force=False):
    """ Get a dict to describe various properties of a named widget. """
    if not force and name not in list_widgets():
        raise ValueError(_("No widget named '%s' exists.") % name)
    base_url = urljoin(script_root() + "/", "widgets/")
    prefix = urljoin(base_url, name)

    widget_class = "".join([p.capitalize() for p in name.split("_")])
    widget_class = "OpenSpending." + widget_class
    return {
        "js": "%s/main.js" % prefix,
        "base": prefix,
        "class_name": widget_class,
        "name": name,
        "preview": prefix + "/preview.png",
    }
Exemple #4
0
def get_widget(name, force=False):
    """ Get a dict to describe various properties of a named widget. """
    if not force and not name in list_widgets():
        raise ValueError(_("No widget named '%s' exists.") % name)
    base_url = urljoin(script_root() + '/', 'widgets/')
    prefix = urljoin(base_url, name)

    widget_class = ''.join([p.capitalize() for p in name.split('_')])
    widget_class = 'OpenSpending.' + widget_class
    return {
        'js': '%s/main.js' % prefix,
        'base': prefix,
        'class_name': widget_class,
        'name': name,
        'preview': prefix + '/preview.png'
        }
def render(path, **kwargs):
    """Render a template with jinja2

    Args:
      path (str): the path to the template; should be of the form
      "dir/filename.html"

    """

    env = Environment()
    env.loader = FileSystemLoader(template_rootdir)
    template = env.get_template(path)


    static_cache_version = config.get("openspending.static_cache_version", "")
    if static_cache_version != "":
        static_cache_version = "?" + static_cache_version

    params = {
        "script_root": h.script_root(),
        "script_boot": h.script_tag('prod/boot'),
        "bootstrap_css": h.static('style/bootstrap.css'),
        "style_css": h.static('style/style.css'),
        "number_symbols_group": c.locale.number_symbols.get('group'),
        "number_symbols_decimal": c.locale.number_symbols.get('decimal'),
        "site_title": app_globals.site_title,
        "static": config.get("openspending.static_path", "/static/"),
        "static_cache_version": static_cache_version,
        "messages": list(h._flash.pop_messages()),
        "languages": languages(c.detected_l10n_languages, c.language),
        "section_active": section_active(c.content_section),
        "account": c.account is not None,
        "h": h,
        "c": c,
        "g": app_globals,
        "can": can,
        "show_rss": hasattr(c, 'show_rss') and c.show_rss or None
        }
    params.update(kwargs)
    form_errors = params.get('form_errors', {})
    return postprocess_forms(template.render(params), form_errors)
Exemple #6
0
def render(path, **kwargs):
    """Render a template with jinja2

    Args:
      path (str): the path to the template; should be of the form
      "dir/filename.html"

    """

    env = Environment()
    env.loader = FileSystemLoader(template_rootdir)
    template = env.get_template(path)

    static_cache_version = config.get("openspending.static_cache_version", "")
    if static_cache_version != "":
        static_cache_version = "?" + static_cache_version

    params = {
        "script_root": h.script_root(),
        "script_boot": h.script_tag('prod/boot'),
        "bootstrap_css": h.static('style/bootstrap.css'),
        "style_css": h.static('style/style.css'),
        "number_symbols_group": c.locale.number_symbols.get('group'),
        "number_symbols_decimal": c.locale.number_symbols.get('decimal'),
        "site_title": app_globals.site_title,
        "static": config.get("openspending.static_path", "/static/"),
        "static_cache_version": static_cache_version,
        "messages": list(h._flash.pop_messages()),
        "languages": languages(c.detected_l10n_languages, c.language),
        "section_active": section_active(c.content_section),
        "account": c.account is not None,
        "h": h,
        "c": c,
        "g": app_globals,
        "can": can,
        "show_rss": hasattr(c, 'show_rss') and c.show_rss or None
    }
    params.update(kwargs)
    form_errors = params.get('form_errors', {})
    return postprocess_forms(template.render(params), form_errors)