Skip to content

Commit

Permalink
fix comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
Akasch committed Jul 10, 2020
1 parent c0059fd commit 69f0d26
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<form method="POST">
{% render_form_header form %}
[...]
</form>

- render a field user of the form 'form':

Expand Down
2 changes: 1 addition & 1 deletion django-spectre-css/templates/spectre-css/form.html
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% render_multi_field field index class+=additional_class class+=field_class id=field_id %}
{% else %}
<div class="form-group">
<label class="form-label" for="{{ field_id }}">{{ label_text }}{# field.label #}</label>
<label class="form-label" for="{{ field_id }}">{{ label_text }}</label>
{% 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 %}
Expand Down
6 changes: 3 additions & 3 deletions django-spectre-css/templatetags/spectre_css.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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}

Expand Down
1 change: 0 additions & 1 deletion django-spectre-css/templatetags/widget_tweaks_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 69f0d26

Please sign in to comment.