Skip to content

Commit 1b15b75

Browse files
committed
Added template tags for messages, form and fields
1 parent 6c55b2c commit 1b15b75

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@ Use in templates
2222

2323
{% load bootstrap_toolkit %}
2424

25+
# Using a filter
26+
2527
<form action="/url/to/submit/" method="post">
2628
{% csrf_token %}
2729
{{ form|as_bootstrap }}
28-
<div class="actions">
30+
<div class="form-actions">
31+
<button type="submit" class="btn primary">Submit</button>
32+
</div>
33+
</form>
34+
35+
# Using template tags
36+
37+
<form action="/url/to/submit/" method="post" class="form">
38+
{% csrf_token %}
39+
{% bootstrap_form form layout="vertical" %}
40+
<div class="form-actions">
2941
<button type="submit" class="btn primary">Submit</button>
3042
</div>
3143
</form>

bootstrap_toolkit/templatetags/bootstrap_toolkit.py

+21
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,25 @@ def split(str, splitter):
210210

211211
@register.simple_tag(takes_context=True)
212212
def bootstrap_messages(context, *args, **kwargs):
213+
"""
214+
Show request messages in Bootstrap style
215+
"""
213216
return get_template("bootstrap_toolkit/messages.html").render(context)
217+
218+
@register.inclusion_tag("bootstrap_toolkit/form.html")
219+
def bootstrap_form(form, **kwargs):
220+
"""
221+
Render a form
222+
"""
223+
context = kwargs.copy()
224+
context['form'] = form
225+
return context
226+
227+
@register.inclusion_tag("bootstrap_toolkit/field.html")
228+
def bootstrap_field(field, **kwargs):
229+
"""
230+
Render a field
231+
"""
232+
context = kwargs.copy()
233+
context['field'] = field
234+
return context

demo_project/demo_app/templates/form_using_template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1>This form uses templates</h1>
2323
{% endif %}
2424
{% endfor %}
2525

26-
{{ form.color|as_bootstrap:layout }}
26+
{% bootstrap_field form.color layout=layout %}
2727

2828
{% if layout == "horizontal" %}
2929
<p class="form-actions">

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

0 commit comments

Comments
 (0)