-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcomponents.py
44 lines (38 loc) · 1.24 KB
/
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.forms.utils import flatatt
from django.utils.safestring import mark_safe
from .utils import render_tag, add_css_class
from .text import text_value
def render_icon(icon, **kwargs):
"""
Render a Bootstrap glyphicon icon
"""
attrs = {
'class': add_css_class(
'icon icon-{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_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">×</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))