Exemplo n.º 1
0
def register_plugin_menu_items(section_name, menu_items):
    """
    Register a list of PluginMenuItem instances for a given menu section (e.g. plugin name)
    """
    new_menu_items = []
    new_menu_item_weight = 100

    nav_menu_items = set()

    for menu_item in menu_items:
        if isinstance(menu_item, PluginMenuItem):
            # translate old-style plugin menu definitions into the new nav-menu items and buttons

            new_menu_button_weight = 100
            new_menu_buttons = []
            for button in menu_item.buttons:
                new_menu_buttons.append(
                    NavMenuButton(
                        link=button.link,
                        title=button.title,
                        icon_class=button.icon_class,
                        button_class=button.color,
                        permissions=button.permissions,
                        weight=new_menu_button_weight,
                    ))
                new_menu_button_weight += 100

            new_menu_items.append(
                NavMenuItem(
                    link=menu_item.link,
                    name=menu_item.link_text,
                    permissions=menu_item.permissions,
                    weight=new_menu_item_weight,
                    buttons=new_menu_buttons,
                ))
            new_menu_item_weight += 100
        elif isinstance(menu_item, NavMenuTab):
            nav_menu_items.add(menu_item)
        else:
            raise TypeError(
                "Top level objects need to be an instance of NavMenuTab or PluginMenuItem: {menu_tab}"
            )

    if new_menu_items:
        # wrap bare item/button list into the default "Plugins" menu tab and appropriate grouping
        if registry["nav_menu"]["tabs"].get("Plugins"):
            weight = (registry["nav_menu"]["tabs"]["Plugins"][list(
                registry["nav_menu"]["tabs"]["Plugins"])[-1]]["weight"] + 100)
        else:
            weight = 100
        nav_menu_items.add(
            NavMenuTab(
                name="Plugins",
                weight=5000,
                groups=(NavMenuGroup(name=section_name,
                                     weight=weight,
                                     items=new_menu_items), ),
            ), )

    register_menu_items(nav_menu_items)
Exemplo n.º 2
0
     name="Dummy Tab",
     weight=150,
     groups=(
         NavMenuGroup(
             name="Dummy Group 1",
             weight=100,
             items=(
                 NavMenuItem(
                     link="plugins:dummy_plugin:dummymodel_list",
                     name="Dummy Model",
                     permissions=["dummy_plugin.view_dummymodel"],
                     buttons=(
                         NavMenuAddButton(
                             link="plugins:dummy_plugin:dummymodel_add",
                             permissions=[
                                 "dummy_plugin.add_dummymodel",
                             ],
                         ),
                         NavMenuImportButton(
                             link="plugins:dummy_plugin:dummymodel_import",
                             permissions=["dummy_plugin.add_dummymodel"],
                         ),
                     ),
                 ),
             ),
         ),
     ),
 ),
 NavMenuTab(
     name="Circuits",
     groups=(
Exemplo n.º 3
0
 groups=(
     NavMenuGroup(
         name="Tags",
         weight=400,
         items=(
             NavMenuItem(
                 link="extras:tag_list",
                 name="Tags",
                 weight=100,
                 permissions=[
                     "extras.view_tags",
                 ],
                 buttons=(
                     NavMenuAddButton(
                         link="extras:tag_add",
                         permissions=[
                             "extras.add_tag",
                         ],
                     ),
                     NavMenuImportButton(
                         link="extras:tag_import",
                         permissions=[
                             "extras.add_tag",
                         ],
                     ),
                 ),
             ),
         ),
     ),
     NavMenuGroup(
         name="Statuses",
         weight=500,
Exemplo n.º 4
0
 weight=100,
 groups=(
     NavMenuGroup(
         name="Tags",
         weight=400,
         items=(NavMenuItem(
             link="extras:tag_list",
             name="Tags",
             weight=100,
             permissions=[
                 "extras.view_tag",
             ],
             buttons=(
                 NavMenuAddButton(
                     link="extras:tag_add",
                     permissions=[
                         "extras.add_tag",
                     ],
                 ),
                 NavMenuImportButton(
                     link="extras:tag_import",
                     permissions=[
                         "extras.add_tag",
                     ],
                 ),
             ),
         ), ),
     ),
     NavMenuGroup(
         name="Statuses",
         weight=500,
         items=(NavMenuItem(
Exemplo n.º 5
0
     name="Example Menu",
     weight=150,
     groups=(
         NavMenuGroup(
             name="Example Group 1",
             weight=100,
             items=(
                 NavMenuItem(
                     link="plugins:example_plugin:examplemodel_list",
                     name="Example Model",
                     permissions=["example_plugin.view_examplemodel"],
                     buttons=(
                         NavMenuAddButton(
                             link="plugins:example_plugin:examplemodel_add",
                             permissions=[
                                 "example_plugin.add_examplemodel",
                             ],
                         ),
                         NavMenuImportButton(
                             link="plugins:example_plugin:examplemodel_import",
                             permissions=["example_plugin.add_examplemodel"],
                         ),
                     ),
                 ),
             ),
         ),
     ),
 ),
 NavMenuTab(
     name="Circuits",
     groups=(
Exemplo n.º 6
0
 groups=(
     NavMenuGroup(
         name="Circuits",
         weight=100,
         items=(
             NavMenuItem(
                 link="circuits:circuit_list",
                 name="Circuits",
                 weight=100,
                 permissions=[
                     "circuits.view_circuit",
                 ],
                 buttons=(
                     NavMenuAddButton(
                         link="circuits:circuit_add",
                         permissions=[
                             "circuits.add_circuit",
                         ],
                     ),
                     NavMenuImportButton(
                         link="circuits:circuit_import",
                         permissions=[
                             "circuits.add_circuit",
                         ],
                     ),
                 ),
             ),
             NavMenuItem(
                 link="circuits:circuittype_list",
                 name="Circuit Types",
                 weight=200,
                 permissions=[
Exemplo n.º 7
0
 groups=(
     NavMenuGroup(
         name="Virtual Machines",
         weight=100,
         items=(
             NavMenuItem(
                 link="virtualization:virtualmachine_list",
                 name="Virtual Machines",
                 weight=100,
                 permissions=[
                     "virtualization.view_virtualmachine",
                 ],
                 buttons=(
                     NavMenuAddButton(
                         link="virtualization:virtualmachine_add",
                         permissions=[
                             "virtualization.add_virtualmachine",
                         ],
                     ),
                     NavMenuImportButton(
                         link="virtualization:virtualmachine_import",
                         permissions=[
                             "virtualization.add_virtualmachine",
                         ],
                     ),
                 ),
             ),
             NavMenuItem(
                 link="virtualization:vminterface_list",
                 name="Interfaces",
                 weight=200,
                 permissions=[
Exemplo n.º 8
0
 groups=(
     NavMenuGroup(
         name="Tenancy",
         weight=300,
         items=(
             NavMenuItem(
                 link="tenancy:tenant_list",
                 name="Tenants",
                 weight=100,
                 permissions=[
                     "tenancy.view_tenant",
                 ],
                 buttons=(
                     NavMenuAddButton(
                         link="tenancy:tenant_add",
                         permissions=[
                             "tenancy.add_tag",
                         ],
                     ),
                     NavMenuImportButton(
                         link="tenancy:tenant_import",
                         permissions=[
                             "tenancy.add_tenant",
                         ],
                     ),
                 ),
             ),
             NavMenuItem(
                 link="tenancy:tenantgroup_list",
                 name="Tenant Groups",
                 weight=200,
                 permissions=[
Exemplo n.º 9
0
 groups=(
     NavMenuGroup(
         name="Sites",
         weight=100,
         items=(
             NavMenuItem(
                 link="dcim:site_list",
                 name="Sites",
                 weight=100,
                 permissions=[
                     "dcim.view_site",
                 ],
                 buttons=(
                     NavMenuAddButton(
                         link="dcim:site_add",
                         permissions=[
                             "dcim.add_site",
                         ],
                     ),
                     NavMenuImportButton(
                         link="dcim:site_import",
                         permissions=[
                             "dcim.add_site",
                         ],
                     ),
                 ),
             ),
             NavMenuItem(
                 link="dcim:region_list",
                 name="Regions",
                 weight=200,
                 permissions=[
Exemplo n.º 10
0
 weight=300,
 groups=(
     NavMenuGroup(
         name="IP Addresses",
         weight=100,
         items=(NavMenuItem(
             link="ipam:ipaddress_list",
             name="IP Addresses",
             weight=100,
             permissions=[
                 "ipam.view_ipaddress",
             ],
             buttons=(
                 NavMenuAddButton(
                     link="ipam:ipaddress_add",
                     permissions=[
                         "ipam.add_ipaddress",
                     ],
                 ),
                 NavMenuImportButton(
                     link="ipam:ipaddress_import",
                     permissions=[
                         "ipam.add_ipaddress",
                     ],
                 ),
             ),
         ), ),
     ),
     NavMenuGroup(
         name="Prefixes",
         weight=200,
         items=(