The horizon.forms Module

class horizon.forms.SelfHandlingMixin(request, *args, **kwargs)

Bases: object

class horizon.forms.SelfHandlingForm(request, *args, **kwargs)

Bases: horizon.forms.base.SelfHandlingMixin, django.forms.forms.Form

A base Form class which includes processing logic in its subclasses.

api_error(message)

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.

base_fields = OrderedDict()
declared_fields = OrderedDict()
media
required_css_class = 'required'
set_warning(message)

Sets a warning on the form.

Unlike NON_FIELD_ERRORS, this doesn’t fail form validation.

class horizon.forms.DateForm(*args, **kwargs)

Bases: django.forms.forms.Form

A simple form for selecting a range of time.

base_fields = OrderedDict([('start', <django.forms.fields.DateField object at 0x7f9f44119d50>), ('end', <django.forms.fields.DateField object at 0x7f9f440c3c10>)])
declared_fields = OrderedDict([('start', <django.forms.fields.DateField object at 0x7f9f44119d50>), ('end', <django.forms.fields.DateField object at 0x7f9f440c3c10>)])
media
class horizon.forms.ModalFormView(*args, **kwargs)

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.

cancel_label = <django.utils.functional.__proxy__ object at 0x7f9f44071e50>
cancel_url = None
form_id = None
form_invalid(form)
form_valid(form)
get_cancel_url()
get_context_data(**kwargs)
get_form(form_class=None)

Returns an instance of the form to be used in this view.

get_object_display(obj)

For dynamic insertion of resources created in modals, this method returns the display name of the created object. Defaults to returning the name attribute.

get_object_id(obj)

For dynamic insertion of resources created in modals, this method returns the id of the created object. Defaults to returning the id attribute.

modal_header = ''
modal_id = None
submit_label = <django.utils.functional.__proxy__ object at 0x7f9f44119ed0>
submit_url = None
class horizon.forms.ModalFormMixin(*args, **kwargs)

Bases: horizon.forms.views.ModalBackdropMixin

get_context_data(**kwargs)
get_template_names()
class horizon.forms.DynamicTypedChoiceField(add_item_link=None, add_item_link_args=None, *args, **kwargs)

Bases: horizon.forms.fields.DynamicChoiceField, django.forms.fields.TypedChoiceField

Simple mix of DynamicChoiceField and TypedChoiceField.

class horizon.forms.DynamicChoiceField(add_item_link=None, add_item_link_args=None, *args, **kwargs)

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.

widget

alias of DynamicSelectWidget

class horizon.forms.ThemableCheckboxInput(attrs=None, check_test=None)

Bases: django.forms.widgets.CheckboxInput

A subclass of the Checkbox widget which renders extra markup to allow a custom checkbox experience.

media
render(name, value, attrs=None)
class horizon.forms.ThemableCheckboxSelectMultiple(*args, **kwargs)

Bases: django.forms.widgets.CheckboxSelectMultiple

media
renderer

alias of ThemableCheckboxFieldRenderer

class horizon.forms.ThemableChoiceField(choices=(), required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)

Bases: django.forms.fields.ChoiceField

Bootstrap based select field.

widget

alias of ThemableSelectWidget

class horizon.forms.ThemableDynamicChoiceField(add_item_link=None, add_item_link_args=None, *args, **kwargs)

Bases: horizon.forms.fields.DynamicChoiceField

widget

alias of ThemableDynamicSelectWidget

class horizon.forms.ThemableSelectWidget(attrs=None, choices=(), data_attrs=(), transform=None, transform_html_attrs=None)

Bases: horizon.forms.fields.SelectWidget

Bootstrap base select field widget.

media
render(name, value, attrs=None, choices=())
class horizon.forms.IPField(*args, **kwargs)

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

version

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)

mask

Boolean flag to validate subnet masks along with IP address. E.g: 10.0.0.1/32

mask_range_from
Subnet range limitation, e.g. 16
That means the input mask will be checked to be in the range
16:max_value. Useful to limit the subnet ranges
to A/B/C-class networks.
clean(value)
invalid_format_message = <django.utils.functional.__proxy__ object at 0x7f9f44069e90>
invalid_mask_message = <django.utils.functional.__proxy__ object at 0x7f9f44069e50>
invalid_version_message = <django.utils.functional.__proxy__ object at 0x7f9f44069d50>
max_v4_mask = 32
max_v6_mask = 128
validate(value)
class horizon.forms.MultiIPField(*args, **kwargs)

Bases: horizon.forms.fields.IPField

Extends IPField to allow comma-separated lists of addresses.

clean(value)
validate(value)
class horizon.forms.SelectWidget(attrs=None, choices=(), data_attrs=(), transform=None, transform_html_attrs=None)

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.

data_attrs

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

transform

A callable used to render the display value from the option object.

transform_html_attrs

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')
    ])
get_data_attrs(option_label)
media
render_option(selected_choices, option_value, option_label)
transform_option_html_attrs(option_label)
transform_option_label(option_label)
exception horizon.forms.ValidationError(message, code=None, params=None)

Bases: exceptions.Exception

An error while validating data.

message_dict
messages
update_error_dict(error_dict)
class horizon.forms.Field(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)

Bases: object

bound_data(data, initial)

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.

clean(value)

Validates the given value and returns its “cleaned” value as an appropriate Python object.

Raises ValidationError for any errors.

creation_counter = 29
default_error_messages = {u'required': <django.utils.functional.__proxy__ object at 0x7f9f45ddf590>}
default_validators = []
empty_values = [None, u'', [], (), {}]
has_changed(initial, data)

Return True if data differs from initial.

hidden_widget

alias of HiddenInput

prepare_value(value)
run_validators(value)
to_python(value)
validate(value)
widget

alias of TextInput

widget_attrs(widget)

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.

class horizon.forms.CharField(max_length=None, min_length=None, *args, **kwargs)

Bases: django.forms.fields.Field

to_python(value)

Returns a Unicode object.

widget_attrs(widget)
class horizon.forms.IntegerField(max_value=None, min_value=None, *args, **kwargs)

Bases: django.forms.fields.Field

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ddf9d0>}
to_python(value)

Validates that int() can be called on the input. Returns the result of int(). Returns None for empty values.

widget

alias of NumberInput

widget_attrs(widget)
class horizon.forms.DateField(input_formats=None, *args, **kwargs)

Bases: django.forms.fields.BaseTemporalField

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ca37d0>}
input_formats = <django.utils.functional.__proxy__ object at 0x7f9f45ca3750>
strptime(value, format)
to_python(value)

Validates that the input can be converted to a date. Returns a Python datetime.date object.

widget

alias of DateInput

class horizon.forms.TimeField(input_formats=None, *args, **kwargs)

Bases: django.forms.fields.BaseTemporalField

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ca3790>}
input_formats = <django.utils.functional.__proxy__ object at 0x7f9f45ca3710>
strptime(value, format)
to_python(value)

Validates that the input can be converted to a time. Returns a Python datetime.time object.

widget

alias of TimeInput

class horizon.forms.DateTimeField(input_formats=None, *args, **kwargs)

Bases: django.forms.fields.BaseTemporalField

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ca38d0>}
input_formats = <django.utils.functional.__proxy__ object at 0x7f9f45ca3810>
prepare_value(value)
strptime(value, format)
to_python(value)

Validates that the input can be converted to a datetime. Returns a Python datetime.datetime object.

widget

alias of DateTimeInput

class horizon.forms.TimeField(input_formats=None, *args, **kwargs)

Bases: django.forms.fields.BaseTemporalField

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ca3790>}
input_formats = <django.utils.functional.__proxy__ object at 0x7f9f45ca3710>
strptime(value, format)
to_python(value)

Validates that the input can be converted to a time. Returns a Python datetime.time object.

widget

alias of TimeInput

class horizon.forms.RegexField(regex, max_length=None, min_length=None, error_message=None, *args, **kwargs)

Bases: django.forms.fields.CharField

regex
class horizon.forms.EmailField(max_length=None, min_length=None, *args, **kwargs)

Bases: django.forms.fields.CharField

clean(value)
default_validators = [<django.core.validators.EmailValidator object at 0x7f9f45e91290>]
widget

alias of EmailInput

class horizon.forms.FileField(*args, **kwargs)

Bases: django.forms.fields.Field

bound_data(data, initial)
clean(data, initial=None)
default_error_messages = {u'contradiction': <django.utils.functional.__proxy__ object at 0x7f9f45cb7190>, u'empty': <django.utils.functional.__proxy__ object at 0x7f9f45ca3bd0>, u'missing': <django.utils.functional.__proxy__ object at 0x7f9f45ca3b50>, u'max_length': <django.utils.functional.__proxy__ object at 0x7f9f45cb7050>, u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ca3c10>}
has_changed(initial, data)
to_python(data)
widget

alias of ClearableFileInput

class horizon.forms.ImageField(*args, **kwargs)

Bases: django.forms.fields.FileField

default_error_messages = {u'invalid_image': <django.utils.functional.__proxy__ object at 0x7f9f45cb71d0>}
to_python(data)

Checks that the file-upload field data contains a valid image (GIF, JPG, PNG, possibly others – whatever the Python Imaging Library supports).

class horizon.forms.URLField(max_length=None, min_length=None, *args, **kwargs)

Bases: django.forms.fields.CharField

clean(value)
default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45cb7210>}
default_validators = [<django.core.validators.URLValidator object at 0x7f9f45cb7310>]
to_python(value)
widget

alias of URLInput

class horizon.forms.BooleanField(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)

Bases: django.forms.fields.Field

has_changed(initial, data)
to_python(value)

Returns a Python boolean object.

validate(value)
widget

alias of CheckboxInput

class horizon.forms.NullBooleanField(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)

Bases: django.forms.fields.BooleanField

A field whose valid values are None, True and False. Invalid values are cleaned to None.

has_changed(initial, data)
to_python(value)

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

validate(value)
widget

alias of NullBooleanSelect

class horizon.forms.ChoiceField(choices=(), required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)

Bases: django.forms.fields.Field

choices
default_error_messages = {u'invalid_choice': <django.utils.functional.__proxy__ object at 0x7f9f45cb7510>}
to_python(value)

Returns a Unicode object.

valid_value(value)

Check to see if the provided value is a valid choice

validate(value)

Validates that the input is in self.choices.

widget

alias of Select

class horizon.forms.MultipleChoiceField(choices=(), required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)

Bases: django.forms.fields.ChoiceField

default_error_messages = {u'invalid_choice': <django.utils.functional.__proxy__ object at 0x7f9f45cb7610>, u'invalid_list': <django.utils.functional.__proxy__ object at 0x7f9f45cb7590>}
has_changed(initial, data)
hidden_widget

alias of MultipleHiddenInput

to_python(value)
validate(value)

Validates that the input is a list or tuple.

widget

alias of SelectMultiple

class horizon.forms.ComboField(fields=(), *args, **kwargs)

Bases: django.forms.fields.Field

A Field whose clean() method calls multiple Field clean() methods.

clean(value)

Validates the given value against all of self.fields, which is a list of Field instances.

class horizon.forms.MultiValueField(fields=(), *args, **kwargs)

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.

clean(value)

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]).

compress(data_list)

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.

default_error_messages = {u'incomplete': <django.utils.functional.__proxy__ object at 0x7f9f45cb7690>, u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45cb7810>}
has_changed(initial, data)
validate(value)
class horizon.forms.FloatField(max_value=None, min_value=None, *args, **kwargs)

Bases: django.forms.fields.IntegerField

default_error_messages = {u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45ddfa90>}
to_python(value)

Validates that float() can be called on the input. Returns the result of float(). Returns None for empty values.

validate(value)
widget_attrs(widget)
class horizon.forms.DecimalField(max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs)

Bases: django.forms.fields.IntegerField

default_error_messages = {u'max_whole_digits': <django.utils.functional.__proxy__ object at 0x7f9f45ca35d0>, u'max_decimal_places': <django.utils.functional.__proxy__ object at 0x7f9f45ca3250>, u'invalid': <django.utils.functional.__proxy__ object at 0x7f9f45e14c10>, u'max_digits': <django.utils.functional.__proxy__ object at 0x7f9f45e14e90>}
to_python(value)

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.

validate(value)
widget_attrs(widget)
class horizon.forms.SplitDateTimeField(input_date_formats=None, input_time_formats=None, *args, **kwargs)

Bases: django.forms.fields.MultiValueField

compress(data_list)
default_error_messages = {u'invalid_time': <django.utils.functional.__proxy__ object at 0x7f9f45cb7910>, u'invalid_date': <django.utils.functional.__proxy__ object at 0x7f9f45cb7ad0>}
hidden_widget

alias of SplitHiddenDateTimeWidget

widget

alias of SplitDateTimeWidget

class horizon.forms.IPAddressField(*args, **kwargs)

Bases: django.forms.fields.CharField

default_validators = [<django.core.validators.RegexValidator object at 0x7f9f45e913d0>]
to_python(value)
class horizon.forms.GenericIPAddressField(protocol=u'both', unpack_ipv4=False, *args, **kwargs)

Bases: django.forms.fields.CharField

to_python(value)
class horizon.forms.FilePathField(path, match=None, recursive=False, allow_files=True, allow_folders=False, required=True, widget=None, label=None, initial=None, help_text=u'', *args, **kwargs)

Bases: django.forms.fields.ChoiceField

class horizon.forms.SlugField(max_length=None, min_length=None, *args, **kwargs)

Bases: django.forms.fields.CharField

clean(value)
default_validators = [<django.core.validators.RegexValidator object at 0x7f9f45e91310>]
class horizon.forms.TypedChoiceField(*args, **kwargs)

Bases: django.forms.fields.ChoiceField

clean(value)
class horizon.forms.TypedMultipleChoiceField(*args, **kwargs)

Bases: django.forms.fields.MultipleChoiceField

clean(value)
validate(value)
class horizon.forms.Media(media=None, **kwargs)

Bases: object

absolute_path(path, prefix=None)
add_css(data)
add_js(data)
render()
render_css()
render_js()
class horizon.forms.MediaDefiningClass

Bases: type

Metaclass for classes that can have media definitions.

class horizon.forms.Widget(attrs=None)

Bases: object

build_attrs(extra_attrs=None, **kwargs)

Helper function for building an attribute dictionary.

id_for_label(id_)

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.

is_hidden
is_localized = False
is_required = False
media
needs_multipart_form = False
render(name, value, attrs=None)

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.

subwidgets(name, value, attrs=None, choices=())

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().

value_from_datadict(data, files, name)

Given a dictionary of data and this widget’s name, returns the value of this widget. Returns None if it’s not provided.

class horizon.forms.TextInput(attrs=None)

Bases: django.forms.widgets.Input

input_type = u'text'
media
class horizon.forms.PasswordInput(attrs=None, render_value=False)

Bases: django.forms.widgets.TextInput

input_type = u'password'
media
render(name, value, attrs=None)
class horizon.forms.HiddenInput(attrs=None)

Bases: django.forms.widgets.Input

input_type = u'hidden'
media
class horizon.forms.MultipleHiddenInput(attrs=None, choices=())

Bases: django.forms.widgets.HiddenInput

A widget that handles <input type=”hidden”> for fields that have a list of values.

media
render(name, value, attrs=None, choices=())
value_from_datadict(data, files, name)
class horizon.forms.ClearableFileInput(attrs=None)

Bases: django.forms.widgets.FileInput

clear_checkbox_id(name)

Given the name of the clear checkbox input, return the HTML id for it.

clear_checkbox_label = <django.utils.functional.__proxy__ object at 0x7f9f45e0cf50>
clear_checkbox_name(name)

Given the name of the file input, return the name of the clear checkbox input.

get_template_substitution_values(value)

Return value-related substitutions.

initial_text = <django.utils.functional.__proxy__ object at 0x7f9f45e0ced0>
input_text = <django.utils.functional.__proxy__ object at 0x7f9f45e0cf10>
is_initial(value)

Return whether value is considered to be initial value.

media
render(name, value, attrs=None)
template_with_clear = u'%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label>'
template_with_initial = u'%(initial_text)s: <a href="%(initial_url)s">%(initial)s</a> %(clear_template)s<br />%(input_text)s: %(input)s'
value_from_datadict(data, files, name)
class horizon.forms.FileInput(attrs=None)

Bases: django.forms.widgets.Input

input_type = u'file'
media
needs_multipart_form = True
render(name, value, attrs=None)
value_from_datadict(data, files, name)

File widgets take data from FILES, not POST

class horizon.forms.DateInput(attrs=None, format=None)

Bases: django.forms.widgets.DateTimeBaseInput

format_key = u'DATE_INPUT_FORMATS'
media
class horizon.forms.DateTimeInput(attrs=None, format=None)

Bases: django.forms.widgets.DateTimeBaseInput

format_key = u'DATETIME_INPUT_FORMATS'
media
class horizon.forms.TimeInput(attrs=None, format=None)

Bases: django.forms.widgets.DateTimeBaseInput

format_key = u'TIME_INPUT_FORMATS'
media
class horizon.forms.Textarea(attrs=None)

Bases: django.forms.widgets.Widget

media
render(name, value, attrs=None)
class horizon.forms.CheckboxInput(attrs=None, check_test=None)

Bases: django.forms.widgets.Widget

media
render(name, value, attrs=None)
value_from_datadict(data, files, name)
class horizon.forms.Select(attrs=None, choices=())

Bases: django.forms.widgets.Widget

allow_multiple_selected = False
media
render(name, value, attrs=None, choices=())
render_option(selected_choices, option_value, option_label)
render_options(choices, selected_choices)
class horizon.forms.NullBooleanSelect(attrs=None)

Bases: django.forms.widgets.Select

A Select Widget intended to be used with NullBooleanField.

media
render(name, value, attrs=None, choices=())
value_from_datadict(data, files, name)
class horizon.forms.SelectMultiple(attrs=None, choices=())

Bases: django.forms.widgets.Select

allow_multiple_selected = True
media
render(name, value, attrs=None, choices=())
value_from_datadict(data, files, name)
class horizon.forms.RadioSelect(*args, **kwargs)

Bases: django.forms.widgets.RendererMixin, django.forms.widgets.Select

media
renderer

alias of RadioFieldRenderer

class horizon.forms.CheckboxSelectMultiple(*args, **kwargs)

Bases: django.forms.widgets.RendererMixin, django.forms.widgets.SelectMultiple

media
renderer

alias of CheckboxFieldRenderer

class horizon.forms.MultiWidget(widgets, attrs=None)

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.

decompress(value)

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.

format_output(rendered_widgets)

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.

id_for_label(id_)
is_hidden
media

Media for a multiwidget is the combination of all media of the subwidgets

needs_multipart_form
render(name, value, attrs=None)
value_from_datadict(data, files, name)
class horizon.forms.SplitDateTimeWidget(attrs=None, date_format=None, time_format=None)

Bases: django.forms.widgets.MultiWidget

A Widget that splits datetime input into two <input type=”text”> boxes.

decompress(value)
media
supports_microseconds = False
class horizon.forms.BaseForm(data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False)

Bases: object

add_error(field, error)

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_initial_prefix(field_name)

Add a ‘initial’ prefix for checking dynamic initial values

add_prefix(field_name)

Returns the field name with a prefix appended, if this Form has a prefix set.

Subclasses may wish to override.

as_p()

Returns this form rendered as HTML <p>s.

as_table()

Returns this form rendered as HTML <tr>s – excluding the <table></table>.

as_ul()

Returns this form rendered as HTML <li>s – excluding the <ul></ul>.

changed_data
clean()

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__’.

errors

Returns an ErrorDict for the data provided for the form

full_clean()

Cleans all of self.data and populates self._errors and self.cleaned_data.

has_changed()

Returns True if data differs from initial.

has_error(field, code=None)
hidden_fields()

Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.

is_multipart()

Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.

is_valid()

Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.

media

Provide a description of all media required to render the widgets on this form

non_field_errors()

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.

visible_fields()

Returns a list of BoundField objects that aren’t hidden fields. The opposite of the hidden_fields() method.

class horizon.forms.Form(data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False)

Bases: django.forms.forms.BaseForm

A collection of Fields, plus their associated data.

base_fields = OrderedDict()
declared_fields = OrderedDict()
media

Previous topic

The horizon.forms.views Module

Next topic

The horizon.forms.fields Module

Project Source

This Page