nautobot.apps.urls - Nautobot Documentation

Skip to content

# `nautobot.apps.urls`

Utilities for apps to implement URL routing.

## `nautobot.apps.urls.NautobotUIViewSetRouter`

Bases: `SimpleRouter`

Nautobot Custom Router that is intended for UI use only.

Source code in `nautobot/core/views/routers.py`

     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    class NautobotUIViewSetRouter(SimpleRouter):
        """
        Nautobot Custom Router that is intended for UI use only.
        """

        routes = [
            Route(
                url=r"^{prefix}/$",
                mapping={"get": "list"},
                name="{basename}_list",
                detail=False,
                initkwargs={"suffix": "List"},
            ),
            Route(
                url=r"^{prefix}/add/$",
                mapping={
                    "get": "create",
                    "post": "create",
                },
                name="{basename}_add",
                detail=False,
                initkwargs={"suffix": "Add"},
            ),
            Route(
                url=r"^{prefix}/import/$",
                mapping={
                    "get": "bulk_create",
                    "post": "bulk_create",
                },
                name="{basename}_import",
                detail=False,
                initkwargs={"suffix": "Import"},
            ),
            Route(
                url=r"^{prefix}/edit/$",
                mapping={
                    "post": "bulk_update",
                },
                name="{basename}_bulk_edit",
                detail=False,
                initkwargs={"suffix": "Bulk Edit"},
            ),
            Route(
                url=r"^{prefix}/delete/$",
                mapping={
                    "post": "bulk_destroy",
                },
                name="{basename}_bulk_delete",
                detail=False,
                initkwargs={"suffix": "Bulk Delete"},
            ),
            DynamicRoute(
                url=r"^{prefix}/{url_path}{trailing_slash}$",
                name="{basename}_{url_name}",
                detail=False,
                initkwargs={},
            ),
            Route(
                url=r"^{prefix}/{lookup}/$",
                mapping={"get": "retrieve"},
                name="{basename}",
                detail=True,
                initkwargs={"suffix": "Detail"},
            ),
            Route(
                url=r"^{prefix}/{lookup}/delete/$",
                mapping={
                    "get": "destroy",
                    "post": "destroy",
                },
                name="{basename}_delete",
                detail=True,
                initkwargs={"suffix": "Delete"},
            ),
            Route(
                url=r"^{prefix}/{lookup}/edit/$",
                mapping={
                    "get": "update",
                    "post": "update",
                },
                name="{basename}_edit",
                detail=True,
                initkwargs={"suffix": "Edit"},
            ),
            # DynamicRoute will handle ChangeLog & Notes UI Views
            DynamicRoute(
                url=r"^{prefix}/{lookup}/{url_path}{trailing_slash}$",
                name="{basename}_{url_name}",
                detail=True,
                initkwargs={},
            ),
        ]