Jump to >

djblets.forms.widgets

Custom widgets for Django form fields.

This module contains widgets that correspond to fields provided in djblets.forms.fields.

class ConditionsWidget(choices, mode_widget, choice_widget, operator_widget, choice_kwargs=None, attrs=None)[source]

A widget used to request a list of conditions from the user.

This is used by ConditionsField() to allow the user to specify a list of possible conditions, composed of choices, operators, and values.

The conditions are displayed as rows of fields. Each row contains a <select> for the condition choice, operator choice, and a choice-provided field for a value.

Additional conditions can be added by the user dynamically.

choices

The condition choices for the field.

Type

djblets.conditions.choices.ConditionChoices

mode_widget

The widget for selecting the mode.

Type

django.forms.widgets.RadioSelect

choice_widget

The widget for selecting choices. One of these will be rendered for every row.

Type

django.forms.widgets.Select

operator_widget

The widget for selecting operators. One of these will be rendered for every row.

Type

django.forms.widgets.Select

choice_kwargs

Optional keyword arguments to pass to each BaseConditionChoice constructor. This is useful for more advanced conditions that need additional data from the form.

This can be updated dynamically by the form during initialization.

Type

dict

template_name = 'djblets_forms/conditions_widget.html'[source]

The name of the template used to render the widget.

value_from_datadict(data, files, name)[source]

Return a value for the field from a submitted form.

This serializes the data POSTed for the form into a format that the field can use and validate.

Parameters
  • data (django.http.request.QueryDict) – The dictionary containing form data.

  • files (django.http.request.QueryDict) – The dictionary containing uploaded files.

  • name (unicode) – The field name for the value to load.

Returns

The value from the form data.

Return type

object

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

Render the widget to HTML.

This will serialize all the choices, operators, and existing conditions and render an HTML representation, along with setting up JavaScript support for configuring the conditions.

Parameters
  • name (unicode) – The base form field name of the widget.

  • value (dict) – The serialized condition set for the field.

  • attrs (dict, optional) – Additional HTML element attributes for the fields.

Returns

The rendered HTML for the widget.

Return type

django.utils.safestring.SafeText

get_context(name, value, attrs)[source]

Return context for the widget.

This will serialize all the choices, operators, and existing conditions needed to render the widget.

Parameters
  • name (unicode) – The base form field name of the widget.

  • value (dict) – The serialized condition set for the field.

  • attrs (dict) – Additional HTML element attributes for the fields.

Returns

The context data for the widget.

Return type

dict

class CopyableTextInput(attrs=None)[source]

A TextInput widget that renders a link to copy its contents.

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

Render the widget.

Parameters
  • name (unicode) – The name of the widget.

  • value (unicode) – The value of the widget.

  • attrs (dict) – The attributes of the widget.

Returns

The rendered widget.

Return type

django.utils.safestring.SafeText

class ListEditWidget(attrs=None, sep=',')[source]

A widget for editing a list of separated values.

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

Render the widget.

Parameters
  • name (unicode) – The field name.

  • value (unicode) – The field value.

  • attrs (dict, optional) – Additional attributes.

Returns

The rendered widget.

Return type

django.utils.safestring.SafeText

id_for_label(id_)[source]

Return the main ID to use for this widget.

This intentionally returns None since there are multiple fields under this widget.

Parameters

id (unicode) – The ID of the element.

Returns

None so that no for= attribute is rendered on the label.

Return type

unicode

class RelatedObjectWidget(multivalued=True)[source]

A base class form widget that lets people select one or more objects.

This is a base class. Extended classes must define their own render() method, to render their own widget with their own data.

This should be used with relatedObjectSelectorView.es6.js, which extends a Backbone view to display data.