pytoolbox.django.forms.utils module¶
Some utilities related to the forms.
- pytoolbox.django.forms.utils.update_widget_attributes(widget, updates)[source]¶
Update attributes of a widget with content of updates handling classes addition [+], removal [-] and toggle [^].
Example usage
>>> from pytoolbox.unittest import asserts >>> widget = type(str(''), (), {}) >>> widget.attrs = {'class': 'mondiale'} >>> update_widget_attributes( ... widget, {'class': '+pigeon +pigeon +voyage -mondiale -mondiale, ^voyage ^voyageur'}) >>> asserts.dict_equal(widget.attrs, {'class': 'pigeon voyageur'}) >>> update_widget_attributes(widget, {'class': '+le', 'cols': 100}) >>> asserts.dict_equal(widget.attrs, {'class': 'le pigeon voyageur', 'cols': 100})
- pytoolbox.django.forms.utils.validate_start_end(form, data=None, start_name='start_date', end_name='end_date')[source]¶
Check that the field containing the value of the start field (time, …) is not bigger (>) than the stop.
- pytoolbox.django.forms.utils.set_disabled(form, field_name, value=False)[source]¶
Toggle the disabled attribute of a form’s field.