Wrap a field within a bootstrap form-group. Additionally sets has-error

    This decorator sets has-error if the field has any errors.

def form_group_wrapped(f):
    """
    Wrap a field within a bootstrap form-group. Additionally sets has-error

    This decorator sets has-error if the field has any errors.
    """
    @wraps(f)
    def wrapped(self, field, *args, **kwargs):
        classes = ['form-group']
        if field.errors:
            classes.append('has-error')

        html = """<div class="{classes}">{rendered_field}</div>""".format(
            classes=' '.join(classes),
            rendered_field=f(self, field, *args, **kwargs)
        )
        return HTMLString(html)

    return wrapped