def render_icon(icon, size='sm', **kwargs):
    """Render a Google icon"""
    attrs = {
        'class': add_css_class(
            'material-icons pmd-{size}'.format(size=size),
            kwargs.get('extra_classes', ''),
        )
    }
    title = kwargs.get('title')
    if title:
        attrs['title'] = title
    return render_tag('i', attrs=attrs, content=icon) def render_alert(content, alert_type=None, dismissable=True):
    """Render a Bootstrap alert"""
    button = ''
    if not alert_type:
        alert_type = 'info'
    css_classes = ['alert', 'alert-' + text_value(alert_type)]
    if dismissable:
        css_classes.append('alert-dismissable')
        button = '<button type="button" class="close" ' + \
                 'data-dismiss="alert" aria-hidden="true">&times;</button>'
    button_placeholder = '__BUTTON__'
    return mark_safe(render_tag(
        'div',
        attrs={'class': ' '.join(css_classes)},
        content=button_placeholder + text_value(content),
    ).replace(button_placeholder, button)) def render_bootstrap_icon(icon, **kwargs):
    """Render a Bootstrap glyphicon icon"""
    attrs = {
        'class': add_css_class(
            'glyphicon glyphicon-{icon}'.format(icon=icon),
            kwargs.get('extra_classes', ''),
        )
    }
    title = kwargs.get('title')
    if title:
        attrs['title'] = title
    return render_tag('span', attrs=attrs) def render_button(content, button_type=None, icon=None, button_class='btn-default', size='',
                  href='', name=None, value=None, title=None, style='default', extra_classes='', _id=''):
    """Render a button with content"""
    return Button(content, button_type, icon, button_class, size, href, name, value, title,
                  style, extra_classes, _id).as_html() def render_field(field, **kwargs):
    """Render a field to a Bootstrap layout"""
    renderer_cls = get_field_renderer(**kwargs)
    return renderer_cls(field, **kwargs).render() def render_form(form, **kwargs):
    """Render a form to a Bootstrap layout"""
    renderer_cls = get_form_renderer(**kwargs)
    return renderer_cls(form, **kwargs).render() def render_formset(formset, **kwargs):
    """
    Render a formset to a Bootstrap layout
    """
    renderer_cls = get_formset_renderer(**kwargs)
    return renderer_cls(formset, **kwargs).render() def render_fab(content, button_type=None, icon=None, button_class='btn-default', size='', href='',
               name=None, value=None, title=None, style='default', extra_classes='', _id=''):
    """Render a button with content"""
    return FAB(content, button_type, icon, button_class, size, href, name, value, title,
               style, extra_classes, _id).as_html() def render_label(content, label_for=None, label_class=None, label_title=''):
    """Render a label with content"""
    attrs = {}
    if label_for:
        attrs['for'] = label_for
    if label_class:
        attrs['class'] = label_class
    if label_title:
        attrs['title'] = label_title
    return render_tag('label', attrs=attrs, content=content) def render_form_errors(form, _type='all', **kwargs):
    """Render form errors to a Bootstrap layout"""
    renderer_cls = get_form_renderer(**kwargs)
    return renderer_cls(form, **kwargs).render_errors(_type) def render_formset_errors(formset, **kwargs):
    """
    Render formset errors to a Bootstrap layout
    """
    renderer_cls = get_formset_renderer(**kwargs)
    return renderer_cls(formset, **kwargs).render_errors() def css_url():
    """
    Return the full url to the Propeller CSS file
    """
    return get_propeller_setting('css_url') or propeller_url('css/bootstrap.min.css') def javascript_url():
    """
    Return the full url to the Propeller JavaScript file
    """
    return get_propeller_setting('javascript_url') or propeller_url('js/bootstrap.min.js') def jquery_url():
    """
    Return the full url to jQuery file to use
    """
    return get_propeller_setting('jquery_url') def theme_url():
    """
    Return the full url to the theme CSS file
    """
    return get_propeller_setting('theme_url') def get_propeller_setting(setting, default=None):
    """
    Read a setting
    """
    return PROPELLER.get(setting, default) def text_value(value):
def text_concat(*args, **kwargs): def url_replace_param(url, name, value):
    """Replace a GET parameter in an URL"""
    url_components = urlparse(force_str(url))
    query_params = parse_qs(url_components.query)
    query_params[name] = value
    query = urlencode(query_params, doseq=True)
    return force_text(urlunparse([
        url_components.scheme,
        url_components.netloc,
        url_components.path,
        url_components.params,
        query,
        url_components.fragment,
    ])) def render_link_tag(url, rel='stylesheet', media=None):
    """Build a link tag"""
    attrs = {
        'href': url,
        'rel': rel,
    }
    if media:
        attrs['media'] = media
    return render_tag('link', attrs=attrs, close=False) def render_tag(tag, attrs=None, content=None, close=True):
    """Render a HTML tag"""
    builder = '<{tag}{attrs}>{content}'
    if content or close:
        builder += '</{tag}>'
    return format_html(
        builder,
        tag=tag,
        attrs=mark_safe(flatatt(attrs)) if attrs else '',
        content=text_value(content),
    ) def render_template_file(template, context=None):
    """Render a Template to unicode"""
    assert isinstance(context, Mapping)
    template = get_template(template)
    return template.render(context)
import re
from math import floor
from django import template
from django.contrib.messages import constants as message_constants
from django.template import Context
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from ..components import render_icon, render_alert, render_bootstrap_icon
from ..forms import (
    render_button, render_field, render_form,
    render_formset, render_fab,
    render_label, render_form_errors, render_formset_errors
)
from ..propeller import (
    css_url, javascript_url, jquery_url, theme_url, get_propeller_setting
)
from ..text import force_text
from ..utils import url_replace_param
from ..utils import render_link_tag, render_tag, render_template_file
    """
    Return the full url to jQuery file to use

    Default value: ``//code.jquery.com/jquery.min.js``

    This value is configurable, see Settings section

    **Tag name**::

        propeller_jquery_url

    **Usage**::

        {% propeller_jquery_url %}

    **Example**::

        {% propeller_jquery_url %}
    """
    return jquery_url()


@register.simple_tag
def propeller_javascript_url():
    """
    Return the full url to the Propeller JavaScript library

    Default value: ``None``

    This value is configurable, see Settings section

    **Tag name**::

        propeller_javascript_url

    **Usage**::

        {% propeller_javascript_url %}

    **Example**::

        {% propeller_javascript_url %}
    """
    return javascript_url()


@register.simple_tag
def propeller_css_url():
    """
    Return the full url to the Propeller CSS library

    Default value: ``None``

    This value is configurable, see Settings section

    **Tag name**::

        propeller_css_url

    **Usage**::

        {% propeller_css_url %}

    **Example**::

        {% propeller_css_url %}
    """
    return css_url()


@register.simple_tag
def propeller_theme_url():
    """
    Return the full url to a Propeller theme CSS library

    Default value: ``None``

    This value is configurable, see Settings section

    **Tag name**::

        propeller_theme_url

    **Usage**::

        {% propeller_theme_url %}

    **Example**::

        {% propeller_theme_url %}
    """
    return theme_url()


@register.simple_tag
def propeller_css():
    """
    Return HTML for Propeller CSS.

    Adjust url in settings. If no url is returned, we don't want this statement
    to return any HTML. This is intended behavior.

    Default value: ``None``

    This value is configurable, see Settings section

    **Tag name**::

        propeller_css

    **Usage**::

        {% propeller_css %}

    **Example**::

        {% propeller_css %}
    """
    rendered_urls = [render_link_tag(propeller_css_url()), ]
    if propeller_theme_url():

        rendered_urls.append(render_link_tag(propeller_theme_url()))