Skip to content

Commit 1c92c45

Browse files
committed
Added bootstrap_messages template tag (fix dyve#57) and improved handling of bootstrap javascript loading
1 parent f77b80a commit 1c92c45

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

bootstrap_toolkit/templatetags/bootstrap_toolkit.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,26 @@ def bootstrap_stylesheet_tag():
4444
return u'<link rel="stylesheet" href="%s">' % bootstrap_stylesheet_url()
4545

4646
@register.simple_tag
47-
def bootstrap_javascript_url(name):
47+
def bootstrap_javascript_url(name=None):
4848
"""
4949
URL to Bootstrap javascript file
5050
"""
5151
if BOOTSTRAP_JS_URL:
5252
return BOOTSTRAP_JS_URL
53-
return BOOTSTRAP_JS_BASE_URL + 'bootstrap-' + name + '.js'
54-
53+
if name:
54+
return BOOTSTRAP_JS_BASE_URL + 'bootstrap-' + name + '.js'
55+
else:
56+
return BOOTSTRAP_JS_BASE_URL + 'bootstrap.min.js'
5557

5658
@register.simple_tag
57-
def bootstrap_javascript_tag(name):
59+
def bootstrap_javascript_tag(name=None):
5860
"""
5961
HTML tag to insert bootstrap_toolkit javascript file
6062
"""
61-
62-
return u'<script src="%s"></script>' % bootstrap_javascript_url(name)
63+
url = bootstrap_javascript_url(name)
64+
if url:
65+
return u'<script src="%s"></script>' % url
66+
return u''
6367

6468
@register.filter
6569
def as_bootstrap(form_or_field, layout='vertical,false'):
@@ -203,3 +207,7 @@ def split(str, splitter):
203207
Split a string
204208
"""
205209
return str.split(splitter)
210+
211+
@register.simple_tag(takes_context=True)
212+
def bootstrap_messages(context, *args, **kwargs):
213+
return get_template("bootstrap_toolkit/messages.html").render(context)

demo_project/demo_app/templates/base.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
1717
<![endif]-->
1818
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
19-
{% bootstrap_javascript_tag "dropdown" %}
20-
{% bootstrap_javascript_tag "alert" %}
19+
{% bootstrap_javascript_tag %}
2120
{% block extra_head %}{% endblock %}
2221
</head>
2322

@@ -50,7 +49,7 @@
5049

5150
<div class="container">
5251

53-
{% include "bootstrap_toolkit/messages.html" %}
52+
{% bootstrap_messages %}
5453

5554
{% block content %}Empty page{% endblock %}
5655

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='django-bootstrap-toolkit',
5-
version='2.6.24',
5+
version='2.7.0',
66
url='https://github.com/dyve/django-bootstrap-toolkit',
77
author='Dylan Verheul',
88
author_email='[email protected]',

0 commit comments

Comments
 (0)