From b50fddabdc6cc84429ae64143ddfd2e61d8dfdbb Mon Sep 17 00:00:00 2001 From: Leif Denby Date: Wed, 4 Dec 2013 15:45:24 +0000 Subject: [PATCH] Handle empty fields gracefully Currently the `|bootstrap` templatetag causes an exception to be fired if used on an undefined form element. I've changed it to just return None if the element is empty. --- bootstrapform/templatetags/bootstrap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bootstrapform/templatetags/bootstrap.py b/bootstrapform/templatetags/bootstrap.py index 3ab5aac..52a19c8 100644 --- a/bootstrapform/templatetags/bootstrap.py +++ b/bootstrapform/templatetags/bootstrap.py @@ -57,7 +57,9 @@ def add_input_classes(field): def render(element, markup_classes): element_type = element.__class__.__name__.lower() - if element_type == 'boundfield': + if element == "": + return None + elif element_type == 'boundfield': add_input_classes(element) template = get_template("bootstrapform/field.html") context = Context({'field': element, 'classes': markup_classes})