trustpoint.formsΒΆ

Contains classes and helpers for forms that can be used in the whole project.

ClassesΒΆ

DisableOptionsSelect

A custom Select widget that allows disabling specific optionsm in a Django ChoiceField dropdown.

Module ContentsΒΆ

class trustpoint.forms.DisableOptionsSelect(attrs=None, disabled_options=None)[source]ΒΆ

Bases: django.forms.Select

A custom Select widget that allows disabling specific optionsm in a Django ChoiceField dropdown.

Example usage:
forms.ChoiceField(

choices=…, widget=DisableOptionsSelect(disabled_options=[β€˜some_value’])

)

Parameters:
  • attrs (dict[str, Any] | None)

  • disabled_options (list[Any] | None)

disabled_options = [][source]ΒΆ
create_option(name, value, label, selected, index, subindex=None, attrs=None)[source]ΒΆ

Create a single option dictionary for rendering.

Overrides the default method to add the disabled attribute for options whose value is in self.disabled_options.

Parameters:
  • name (str) – Name of the form field.

  • value (Any) – Value of the option.

  • label (int | str) – Display label for the option.

  • selected (bool) – Whether the option is selected.

  • index (int) – Index of the option.

  • subindex (int | None) – Optional subindex for optgroups.

  • attrs (dict[str, Any] | None) – Additional HTML attributes.

Returns:

A dictionary representing the option to render.

Return type:

dict[str, Any]