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.
-
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.
-
-
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
= {}¶
-
-
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, …).
-
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.
-
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.
-
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
= ()¶
-
-
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
-