def field_html_code(field, main_class='col-md-6 col-xs-8', flag_error_text=True, flag_help_text=True): """ Usage: {% field_html_code field 'col-md-6 col-xs-8' %} """ tmp_div = Template(""" <div class="$main_class"> <div class="form-group $has_error"> <label class="control-label" for="$field_auto_id">$field_label</label> $field $field_errors $field_help_text </div> </div> """) has_error = 'has-error' if field.errors else '' field_errors = '' if field.errors and flag_error_text: field_errors = '<span class="help-block">%s</span>\n' % striphtml(str(field.errors)).capitalize() field_help_text = '' if flag_help_text: field_help_text = '<span class="help-block">%s</span>\n' % (field.help_text.capitalize()) htmlcell = tmp_div.substitute( main_class=main_class, has_error=has_error, field_auto_id=field.auto_id, field_label=word_capital(field.label), field=str(field).decode("utf-8"), field_errors=field_errors, field_help_text=field_help_text) return mark_safe(htmlcell)
def wordcap(value): """ Capitalizes the first character of each words. """ return word_capital(value)