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=(), data_attrs=(), transform=None, transform_html_attrs=None)[source]

Bases: horizon.forms.fields.SelectWidget

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.ExternalFileField(*args, **kwargs)[source]

Bases: django.forms.fields.FileField

A special flavor of FileField which is meant to be used in cases when instead of uploading file to Django it should be uploaded to some external location, while the form validation is done as usual. Should be paired with ExternalUploadMeta metaclass embedded into the Form class.

class horizon.forms.fields.ExternalUploadMeta[source]

Bases: django.forms.forms.DeclarativeFieldsMetaclass

Set this class as the metaclass of a form that contains ExternalFileField in order to process ExternalFileField fields in a specific way. A hidden CharField twin of FieldField is created which contains just the filename (if any file was selected on browser side) and a special clean method for FileField is defined which extracts just file name. This allows to avoid actual file upload to Django server, yet process form clean() phase as usual. Actual file upload happens entirely on client-side.

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 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)[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.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)[source]
media
render_option(selected_choices, option_value, option_label)[source]
transform_option_html_attrs(option_label)[source]
transform_option_label(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

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

Bases: django.forms.fields.ChoiceField

Bootstrap based select field.

widget

alias of ThemableSelectWidget

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

Bases: horizon.forms.fields.DynamicChoiceField

widget

alias of ThemableDynamicSelectWidget

class horizon.forms.fields.ThemableDynamicSelectWidget(attrs=None, choices=(), data_attrs=(), transform=None, transform_html_attrs=None)[source]

Bases: horizon.forms.fields.ThemableSelectWidget, horizon.forms.fields.DynamicSelectWidget

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

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

Simple mix of ThemableDynamicChoiceField & TypedChoiceField.

class horizon.forms.fields.ThemableSelectWidget(attrs=None, choices=(), data_attrs=(), transform=None, transform_html_attrs=None)[source]

Bases: horizon.forms.fields.SelectWidget

Bootstrap base select field widget.

media
render(name, value, attrs=None, choices=())[source]

Previous topic

The horizon.forms Module

Next topic

The horizon.forms.base Module

Project Source

This Page