Bases: object
Bases: horizon.forms.base.SelfHandlingMixin, django.forms.forms.Form
A base Form class which includes processing logic in its subclasses.
Adds an error to the form’s error dictionary after validation based on problems reported via the API. This is useful when you wish for API errors to appear as errors on the form rather than using the messages framework.
Sets a warning on the form.
Unlike NON_FIELD_ERRORS, this doesn’t fail form validation.
Bases: django.forms.forms.Form
A simple form for selecting a range of time.
Bases: horizon.forms.views.ModalFormMixin, horizon.views.HorizonFormView
The main view class from which all views which handle forms in Horizon should inherit. It takes care of all details with processing SelfHandlingForm classes, and modal concerns when the associated template inherits from horizon/common/_modal_form.html.
Subclasses must define a form_class and template_name attribute at minimum.
See Django’s documentation on the FormView class for more details.
Returns an instance of the form to be used in this view.
For dynamic insertion of resources created in modals, this method returns the display name of the created object. Defaults to returning the name attribute.
For dynamic insertion of resources created in modals, this method returns the id of the created object. Defaults to returning the id attribute.
Bases: horizon.forms.views.ModalBackdropMixin
Bases: horizon.forms.fields.DynamicChoiceField, django.forms.fields.TypedChoiceField
Simple mix of DynamicChoiceField and TypedChoiceField.
Bases: django.forms.fields.ChoiceField
A subclass of ChoiceField with additional properties that make dynamically updating its elements easier.
Notably, the field declaration takes an extra argument, add_item_link which may be a string or callable defining the URL that should be used for the “add” link associated with the field.
alias of DynamicSelectWidget
Bases: django.forms.widgets.CheckboxInput
A subclass of the Checkbox widget which renders extra markup to allow a custom checkbox experience.
Bases: django.forms.widgets.CheckboxSelectMultiple
alias of ThemableCheckboxFieldRenderer
Bases: django.forms.fields.ChoiceField
Bootstrap based select field.
alias of ThemableSelectWidget
Bases: horizon.forms.fields.DynamicChoiceField
alias of ThemableDynamicSelectWidget
Bases: horizon.forms.fields.SelectWidget
Bootstrap base select field widget.
Bases: django.forms.fields.Field
Form field for entering IP/range values, with validation. Supports IPv4/IPv6 in the format: .. xxx.xxx.xxx.xxx .. xxx.xxx.xxx.xxx/zz .. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff .. ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/zz and all compressed forms. Also the short forms are supported: xxx/yy xxx.xxx/yy
Specifies which IP version to validate, valid values are 1 (fields.IPv4), 2 (fields.IPv6) or both - 3 (fields.IPv4 | fields.IPv6). Defaults to IPv4 (1)
Boolean flag to validate subnet masks along with IP address. E.g: 10.0.0.1/32
Bases: horizon.forms.fields.IPField
Extends IPField to allow comma-separated lists of addresses.
Bases: django.forms.widgets.Select
Customizable select widget, that allows to render data-xxx attributes from choices. This widget also allows user to specify additional html attributes for choices.
Specifies object properties to serialize as data-xxx attribute. If passed (‘id’, ), this will be rendered as: <option data-id=”123”>option_value</option> where 123 is the value of choice_value.id
A callable used to render the display value from the option object.
A callable used to render additional HTML attributes for the option object. It returns a dictionary containing the html attributes and their values. For example, to define a title attribute for the choices:
helpText = { 'Apple': 'This is a fruit',
'Carrot': 'This is a vegetable' }
def get_title(data):
text = helpText.get(data, None)
if text:
return {'title': text}
else:
return {}
....
....
widget=forms.ThemableSelect( attrs={'class': 'switchable',
'data-slug': 'source'},
transform_html_attrs=get_title )
self.fields[<field name>].choices =
([
('apple','Apple'),
('carrot','Carrot')
])
Bases: exceptions.Exception
An error while validating data.
Bases: object
Return the value that should be shown for this field on render of a bound form, given the submitted POST data for the field and the initial data, if any.
For most fields, this will simply be data; FileFields need to handle it a bit differently.
Validates the given value and returns its “cleaned” value as an appropriate Python object.
Raises ValidationError for any errors.
Return True if data differs from initial.
alias of HiddenInput
alias of TextInput
Given a Widget instance (not a Widget class), returns a dictionary of any HTML attributes that should be added to the Widget, based on this Field.
Bases: django.forms.fields.Field
Returns a Unicode object.
Bases: django.forms.fields.Field
Validates that int() can be called on the input. Returns the result of int(). Returns None for empty values.
alias of NumberInput
Bases: django.forms.fields.BaseTemporalField
Validates that the input can be converted to a date. Returns a Python datetime.date object.
alias of DateInput
Bases: django.forms.fields.BaseTemporalField
Validates that the input can be converted to a time. Returns a Python datetime.time object.
alias of TimeInput
Bases: django.forms.fields.BaseTemporalField
Validates that the input can be converted to a datetime. Returns a Python datetime.datetime object.
alias of DateTimeInput
Bases: django.forms.fields.BaseTemporalField
Validates that the input can be converted to a time. Returns a Python datetime.time object.
alias of TimeInput
Bases: django.forms.fields.CharField
Bases: django.forms.fields.CharField
alias of EmailInput
Bases: django.forms.fields.Field
alias of ClearableFileInput
Bases: django.forms.fields.FileField
Checks that the file-upload field data contains a valid image (GIF, JPG, PNG, possibly others – whatever the Python Imaging Library supports).
Bases: django.forms.fields.CharField
alias of URLInput
Bases: django.forms.fields.Field
Returns a Python boolean object.
alias of CheckboxInput
Bases: django.forms.fields.BooleanField
A field whose valid values are None, True and False. Invalid values are cleaned to None.
Explicitly checks for the string ‘True’ and ‘False’, which is what a hidden field will submit for True and False, for ‘true’ and ‘false’, which are likely to be returned by JavaScript serializations of forms, and for ‘1’ and ‘0’, which is what a RadioField will submit. Unlike the Booleanfield we need to explicitly check for True, because we are not using the bool() function
alias of NullBooleanSelect
Bases: django.forms.fields.Field
Returns a Unicode object.
Check to see if the provided value is a valid choice
Validates that the input is in self.choices.
alias of Select
Bases: django.forms.fields.ChoiceField
alias of MultipleHiddenInput
Validates that the input is a list or tuple.
alias of SelectMultiple
Bases: django.forms.fields.Field
A Field whose clean() method calls multiple Field clean() methods.
Validates the given value against all of self.fields, which is a list of Field instances.
Bases: django.forms.fields.Field
A Field that aggregates the logic of multiple Fields.
Its clean() method takes a “decompressed” list of values, which are then cleaned into a single value according to self.fields. Each value in this list is cleaned by the corresponding field – the first value is cleaned by the first field, the second value is cleaned by the second field, etc. Once all fields are cleaned, the list of clean values is “compressed” into a single value.
Subclasses should not have to implement clean(). Instead, they must implement compress(), which takes a list of valid values and returns a “compressed” version of those values – a single value.
You’ll probably want to use this with MultiWidget.
Validates every value in the given list. A value is validated against the corresponding Field in self.fields.
For example, if this MultiValueField was instantiated with fields=(DateField(), TimeField()), clean() would call DateField.clean(value[0]) and TimeField.clean(value[1]).
Returns a single value for the given list of values. The values can be assumed to be valid.
For example, if this MultiValueField was instantiated with fields=(DateField(), TimeField()), this might return a datetime object created by combining the date and time in data_list.
Bases: django.forms.fields.IntegerField
Validates that float() can be called on the input. Returns the result of float(). Returns None for empty values.
Bases: django.forms.fields.IntegerField
Validates that the input is a decimal number. Returns a Decimal instance. Returns None for empty values. Ensures that there are no more than max_digits in the number, and no more than decimal_places digits after the decimal point.
Bases: django.forms.fields.MultiValueField
alias of SplitHiddenDateTimeWidget
alias of SplitDateTimeWidget
Bases: django.forms.fields.CharField
Bases: django.forms.fields.CharField
Bases: django.forms.fields.ChoiceField
Bases: django.forms.fields.CharField
Bases: django.forms.fields.ChoiceField
Bases: django.forms.fields.MultipleChoiceField
Bases: object
Bases: type
Metaclass for classes that can have media definitions.
Bases: object
Helper function for building an attribute dictionary.
Returns the HTML ID attribute of this Widget for use by a <label>, given the ID of the field. Returns None if no ID is available.
This hook is necessary because some widgets have multiple HTML elements and, thus, multiple IDs. In that case, this method should return an ID value that corresponds to the first ID in the widget’s tags.
Returns this Widget rendered as HTML, as a Unicode string.
The ‘value’ given is not guaranteed to be valid input, so subclass implementations should program defensively.
Yields all “subwidgets” of this widget. Used only by RadioSelect to allow template access to individual <input type=”radio”> buttons.
Arguments are the same as for render().
Given a dictionary of data and this widget’s name, returns the value of this widget. Returns None if it’s not provided.
Bases: django.forms.widgets.Input
Bases: django.forms.widgets.TextInput
Bases: django.forms.widgets.Input
Bases: django.forms.widgets.HiddenInput
A widget that handles <input type=”hidden”> for fields that have a list of values.
Bases: django.forms.widgets.FileInput
Given the name of the clear checkbox input, return the HTML id for it.
Given the name of the file input, return the name of the clear checkbox input.
Return value-related substitutions.
Return whether value is considered to be initial value.
Bases: django.forms.widgets.Input
File widgets take data from FILES, not POST
Bases: django.forms.widgets.DateTimeBaseInput
Bases: django.forms.widgets.DateTimeBaseInput
Bases: django.forms.widgets.DateTimeBaseInput
Bases: django.forms.widgets.Widget
Bases: django.forms.widgets.Widget
Bases: django.forms.widgets.Widget
Bases: django.forms.widgets.Select
A Select Widget intended to be used with NullBooleanField.
Bases: django.forms.widgets.Select
Bases: django.forms.widgets.RendererMixin, django.forms.widgets.Select
alias of RadioFieldRenderer
Bases: django.forms.widgets.RendererMixin, django.forms.widgets.SelectMultiple
alias of CheckboxFieldRenderer
Bases: django.forms.widgets.Widget
A widget that is composed of multiple widgets.
Its render() method is different than other widgets’, because it has to figure out how to split a single value for display in multiple widgets. The value argument can be one of two things:
- A list.
- A normal value (e.g., a string) that has been “compressed” from a list of values.
In the second case – i.e., if the value is NOT a list – render() will first “decompress” the value into a list before rendering it. It does so by calling the decompress() method, which MultiWidget subclasses must implement. This method takes a single “compressed” value and returns a list.
When render() does its HTML rendering, each value in the list is rendered with the corresponding widget – the first value is rendered in the first widget, the second value is rendered in the second widget, etc.
Subclasses may implement format_output(), which takes the list of rendered widgets and returns a string of HTML that formats them any way you’d like.
You’ll probably want to use this class with MultiValueField.
Returns a list of decompressed values for the given compressed value. The given value can be assumed to be valid, but not necessarily non-empty.
Given a list of rendered widgets (as strings), returns a Unicode string representing the HTML for the whole lot.
This hook allows you to format the HTML design of the widgets, if needed.
Media for a multiwidget is the combination of all media of the subwidgets
Bases: django.forms.widgets.MultiWidget
A Widget that splits datetime input into two <input type=”text”> boxes.
Bases: object
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If its value is None the errors will be treated as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. What we define as an “error” can be either a simple string or an instance of ValidationError with its message attribute set and what we define as list or dictionary can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
Add a ‘initial’ prefix for checking dynamic initial values
Returns the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
Returns this form rendered as HTML <p>s.
Returns this form rendered as HTML <tr>s – excluding the <table></table>.
Returns this form rendered as HTML <li>s – excluding the <ul></ul>.
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
Returns an ErrorDict for the data provided for the form
Cleans all of self.data and populates self._errors and self.cleaned_data.
Returns True if data differs from initial.
Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.
Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.
Provide a description of all media required to render the widgets on this form
Returns an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Returns an empty ErrorList if there are none.
Returns a list of BoundField objects that aren’t hidden fields. The opposite of the hidden_fields() method.
Bases: django.forms.forms.BaseForm
A collection of Fields, plus their associated data.