The horizon.forms.fields Module

class horizon.forms.fields.DynamicChoiceField(add_item_link=None, add_item_link_args=None, *args, **kwargs)[source]

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.fields.DynamicSelectWidget(attrs=None, choices=())[source]

Bases: django.forms.widgets.Select

A subclass of the Select widget which renders extra attributes for use in callbacks to handle dynamic changes to the available choices.

get_add_item_url()[source]
media
render(*args, **kwargs)[source]
class horizon.forms.fields.DynamicTypedChoiceField(add_item_link=None, add_item_link_args=None, *args, **kwargs)[source]

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

Simple mix of DynamicChoiceField and TypedChoiceField.

class horizon.forms.fields.IPField(*args, **kwargs)[source]

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)[source]
invalid_format_message = <django.utils.functional.__proxy__ object at 0x7faf8a5c6a10>
invalid_mask_message = <django.utils.functional.__proxy__ object at 0x7faf8a5c6a90>
invalid_version_message = <django.utils.functional.__proxy__ object at 0x7faf8a5c6a50>
max_v4_mask = 32
max_v6_mask = 128
validate(value)[source]
class horizon.forms.fields.MultiIPField(*args, **kwargs)[source]

Bases: horizon.forms.fields.IPField

Extends IPField to allow comma-separated lists of addresses.

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

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.SelectWidget( attrs={'class': 'switchable',
                                 'data-slug': 'source'},
                        transform_html_attrs=get_title )

self.fields[<field name>].choices =
    ([
        ('apple','Apple'),
        ('carrot','Carrot')
    ])
media
render_option(selected_choices, option_value, option_label)[source]
class horizon.forms.fields.ThemableCheckboxChoiceInput(*args, **kwargs)[source]

Bases: django.forms.widgets.CheckboxChoiceInput

render(name=None, value=None, attrs=None, choices=())[source]
class horizon.forms.fields.ThemableCheckboxFieldRenderer(name, value, attrs, choices)[source]

Bases: django.forms.widgets.CheckboxFieldRenderer

choice_input_class

alias of ThemableCheckboxChoiceInput

class horizon.forms.fields.ThemableCheckboxInput(attrs=None, check_test=None)[source]

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)[source]
class horizon.forms.fields.ThemableCheckboxSelectMultiple(*args, **kwargs)[source]

Bases: django.forms.widgets.CheckboxSelectMultiple

media
renderer

alias of ThemableCheckboxFieldRenderer

Previous topic

The horizon.contrib Module

Next topic

The horizon.forms.views Module

Project Source

This Page