pytoolbox.django.forms.mixins module

Mix-ins for building your own forms.

class pytoolbox.django.forms.mixins.ConvertEmailToTextMixin(*args, **kwargs)[source]

Bases: object

Set email inputs as text to avoid the i18n issue http://html5doctor.com/html5-forms-input-types#input-email.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class pytoolbox.django.forms.mixins.EnctypeMixin[source]

Bases: object

enctype
class pytoolbox.django.forms.mixins.HelpTextToPlaceholderMixin(*args, **kwargs)[source]

Bases: object

Update the widgets of the form to copy (and remove) the field’s help text to the widget’s placeholder.

placeholder_fields = (<class 'django.forms.fields.CharField'>, <class 'django.forms.fields.DateField'>, <class 'django.forms.fields.DateTimeField'>, <class 'django.forms.fields.DecimalField'>, <class 'django.forms.fields.EmailField'>, <class 'django.forms.fields.FloatField'>, <class 'django.forms.fields.IntegerField'>, <class 'django.forms.fields.RegexField'>, <class 'django.forms.fields.SlugField'>, <class 'django.forms.fields.TimeField'>)

Add a placeholder to the type of fields listed here.

placeholder_remove_help_text = True

Remove the help text after having copied it to the placeholder.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

set_placeholder(name, field)[source]
class pytoolbox.django.forms.mixins.MapErrorsMixin[source]

Bases: object

Map errors based on field name. Mandatory when the form contains a field from a model named differently.

errors_map = {}
add_error(field, error)[source]
class pytoolbox.django.forms.mixins.ModelBasedFormCleanupMixin[source]

Bases: object

Make possible the cleanup of the form by the model through a class method called clean_form. Useful to cleanup the form based on complex conditions, e.g. if two fields are inter-related (start/end dates, …).

clean()[source]
class pytoolbox.django.forms.mixins.RequestMixin(*args, **kwargs)[source]

Bases: object

Accept request as a optional (default: None) argument of the constructor and set it as an attribute of the object.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class pytoolbox.django.forms.mixins.CreatedByMixin(*args, **kwargs)[source]

Bases: pytoolbox.django.forms.mixins.RequestMixin

Set instance’s created_by field to current user if the instance is just created.

save(commit=True)[source]
class pytoolbox.django.forms.mixins.StaffOnlyFieldsMixin(*args, **kwargs)[source]

Bases: pytoolbox.django.forms.mixins.RequestMixin

Hide some fields if authenticated user is not a member of the staff.

staff_only_fields = ()
__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class pytoolbox.django.forms.mixins.UpdateWidgetAttributeMixin(*args, **kwargs)[source]

Bases: object

Update the widgets of the form based on a set of rules applied depending of the form field’s class. The rules can change the class of the widget and/or update the attributes of the widget with pytoolbox.django.forms.utils.update_widget_attributes().

widgets_rules = {<class 'django.forms.fields.DateField'>: [<class 'pytoolbox.django.forms.widgets.CalendarDateInput'>, {'class': '+dateinput +input-small'}], <class 'django.forms.fields.TimeField'>: [<class 'pytoolbox.django.forms.widgets.ClockTimeInput'>, {'class': '+timeinput +input-small'}]}
widgets_common_attrs = {}

Attributes that are applied to all widgets of the form

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.