diff --git a/README.md b/README.md index 7ffe737..8c0ee6f 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,22 @@ add it to your installed apps: 'django-spectre-css', ] -## Examples: -This module defines the following tags to make displaying Forms easier. +## Warning The help_text from models is marked as save in the template and therefore it is possible to have html e.g. links in the help_text. +This means that help_text of an ModelField should never be directly based on user input. + +## Examples: +This module defines the following tags to make displaying forms easier. + +- render the form header (csrf-token and non-field errors) for the form 'form': + + + {% load spectre_css %} +
+ {% render_form_header form %} + [...] +
- render a field user of the form 'form': diff --git a/django-spectre-css/templates/spectre-css/form-haeder.html b/django-spectre-css/templates/spectre-css/form-header.html similarity index 100% rename from django-spectre-css/templates/spectre-css/form-haeder.html rename to django-spectre-css/templates/spectre-css/form-header.html diff --git a/django-spectre-css/templates/spectre-css/form.html b/django-spectre-css/templates/spectre-css/form.html index 377fa04..582cbb3 100644 --- a/django-spectre-css/templates/spectre-css/form.html +++ b/django-spectre-css/templates/spectre-css/form.html @@ -1,6 +1,6 @@ {% load widget_tweaks %} -{% include 'spectre-css/form-haeder.html' %} +{% include 'spectre-css/form-header.html' %} {% for field in form.visible_fields %} {% include 'spectre-css/generic-field.html' with field=field %} diff --git a/django-spectre-css/templates/spectre-css/render-multi-field-part.html b/django-spectre-css/templates/spectre-css/render-multi-field-part.html index 7bd1e61..a28f57c 100644 --- a/django-spectre-css/templates/spectre-css/render-multi-field-part.html +++ b/django-spectre-css/templates/spectre-css/render-multi-field-part.html @@ -3,7 +3,7 @@ {% render_multi_field field index class+=additional_class class+=field_class id=field_id %} {% else %}
- + {% if field.form.is_bound %} {% if field.errors %} {% render_multi_field field index class+=additional_class class+="is-error" class+=field_class id=field_id %} diff --git a/django-spectre-css/templatetags/spectre_css.py b/django-spectre-css/templatetags/spectre_css.py index 0175b52..ef3e770 100644 --- a/django-spectre-css/templatetags/spectre_css.py +++ b/django-spectre-css/templatetags/spectre_css.py @@ -1,6 +1,6 @@ from typing import List, Tuple, Optional, Union -from django.forms import Form +from django.forms import Form, MultiValueField from django.forms.boundfield import BoundField from django.forms.models import ModelChoiceIterator from django.forms.widgets import Select, CheckboxInput @@ -21,7 +21,7 @@ def is_select(field): @register.filter def is_multi_field(field: BoundField): - return "fields" in field.field.__dict__ + return isinstance(field, MultiValueField) field_value = Union[str, int, None] @@ -86,7 +86,7 @@ def render_form(form: Form): return {'form': form} -@register.inclusion_tag('spectre-css/form-haeder.html') +@register.inclusion_tag('spectre-css/form-header.html') def render_form_header(form: Form): return {'form': form} diff --git a/django-spectre-css/templatetags/widget_tweaks_extras.py b/django-spectre-css/templatetags/widget_tweaks_extras.py index 3cc9972..a90014f 100644 --- a/django-spectre-css/templatetags/widget_tweaks_extras.py +++ b/django-spectre-css/templatetags/widget_tweaks_extras.py @@ -62,7 +62,6 @@ def render(self, context): widget = bounded_field.field.widget.widgets[index] attrs = widget.attrs.copy() - print(attrs) for k, v in self.set_attrs: attrs[k] = v.resolve(context) for k, v in self.append_attrs: