Skip to content

# `nautobot.apps.choices`

Utilities for implementing choices.

## `nautobot.apps.choices.BannerClassChoices`

Bases: `ChoiceSet`

Styling choices for custom banners.

## `nautobot.apps.choices.ButtonActionColorChoices`

Bases: `ChoiceSet`

Map standard button actions to Bootstrap color classes.

## `nautobot.apps.choices.ButtonActionIconChoices`

Bases: `ChoiceSet`

Map standard button actions to Material Design Icons classes.

## `nautobot.apps.choices.ChoiceSet`

Base class for defining choices for a model and/or menu.

Subclasses should define a CHOICES constant which consists of a list of tuples of the form `(value, display_str)`, or optionally as tuples of the form `(grouping, ((value, display_str), (value, display_str), ...))`.

Example

    class GreekCapitalLetterChoices(ChoiceSet):
        ALPHA = "A"
        BETA = "B"
        GAMMA = "Γ"

        CHOICES = (
            (ALPHA, "alpha"),
            (BETA, "beta"),
            (GAMMA, "gamma"),
        )

### `as_dict()` `classmethod`

Get a dictionary representation of this ChoiceSet's `CHOICES`.

### `values()` `classmethod`

Get a flat list of all values defined in this ChoiceSet's `CHOICES`.

## `nautobot.apps.choices.JobResultStatusChoices`

Bases: `ChoiceSet`

These status choices are using the same taxonomy as within Celery core. A Nautobot Job status is equivalent to a Celery task state.

### `precedence(state)` `staticmethod`

Get the precedence for a state. Lower index means higher precedence.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`state` | `str` | One of the status choices. | required

Returns:

Type | Description
--- | ---
`int` | Precedence value.

Examples:

    >>> JobResultStatusChoices.precedence(JobResultStatusChoices.STATUS_SUCCESS)
    0

## `nautobot.apps.choices.unpack_grouped_choices(choices)`

Unpack a grouped choices hierarchy into a flat list of two-tuples. For example:

choices = ( ('Foo', ( (1, 'A'), (2, 'B') )), ('Bar', ( (3, 'C'), (4, 'D') )) )

becomes:

choices = ( (1, 'A'), (2, 'B'), (3, 'C'), (4, 'D') )