def render_errors(self): formset_errors = self.get_formset_errors() if formset_errors: return render_template_file( 'bootstrap4/form_errors.html', context={ 'errors': formset_errors, 'form': self.formset, 'layout': self.layout, } ) return ''
def append_to_field(self, html): help_text_and_errors = [] if self.field_help: help_text_and_errors.append(self.field_help) help_text_and_errors += self.field_errors if help_text_and_errors: help_html = render_template_file( 'bootstrap4/field_help_text_and_errors.html', context={ 'field': self.field, 'help_text_and_errors': help_text_and_errors, 'layout': self.layout, } ) html += '<span class="form-text text-muted">{help}</span>'.format(help=help_html) return html
def render_errors(self, type='all'): form_errors = None if type == 'all': form_errors = self.get_fields_errors() + self.form.non_field_errors() elif type == 'fields': form_errors = self.get_fields_errors() elif type == 'non_fields': form_errors = self.form.non_field_errors() if form_errors: return render_template_file( 'bootstrap4/form_errors.html', context={ 'errors': form_errors, 'form': self.form, 'layout': self.layout, } ) return ''
def bootstrap_messages(context, *args, **kwargs): """ Show django.contrib.messages Messages in Bootstrap alert containers. In order to make the alerts dismissable (with the close button), we have to set the jquery parameter too when using the bootstrap_javascript tag. Uses the template ``bootstrap4/messages.html``. **Tag name**:: bootstrap_messages **Parameters**: None. **Usage**:: {% bootstrap_messages %} **Example**:: {% bootstrap_javascript jquery=1 %} {% bootstrap_messages %} """ if Context and isinstance(context, Context): context = context.flatten() context.update({'message_constants': message_constants}) return render_template_file('bootstrap4/messages.html', context=context)
def render_errors(self, type="all"): form_errors = None if type == "all": form_errors = self.get_fields_errors() + self.form.non_field_errors() elif type == "fields": form_errors = self.get_fields_errors() elif type == "non_fields": form_errors = self.form.non_field_errors() if self.required_css_class != 'not_message': if form_errors: return render_template_file( "bootstrap4/form_errors.html", context={ "errors": form_errors, "form": self.form, "layout": self.layout, "type": type, }, ) return ""