conjunto.menu

conjunto.menu.IActionButton

Bases: MenuItemInterfaceMixin

An action button that can be added to an e.g. table row.

Attributes:
  • view_name (str) –

    The name of the view that should be called when this button is clicked. It will get the current row's object as param.

  • method

    the method to call the request: "get" (default) or "post".

conjunto.menu.IMenuItem

Bases: MenuItemInterfaceMixin

An extendable and versatile MenuItem Interface

You can use that for creating menu items in a named menu:

class AddUserAction(IMenuItem)
    menu = "page_actions"
    title = _("Add user")
    url = reverse_lazy("user:delete")
    icon = "user-delete"
Attributes:
  • url (str) –

    the URL to call when this menu item is clicked.

  • separator (bool) –

    if True, this menu item has a separator after it.

  • badge (str) –

    a callable that returns a string to be displayed in a badge.

  • exact_url (bool) –

    if True, the active class will only get added on the menu item if the browser path matches exactly the MenuItem URL. If False (default), it also is active when child items are selected.

  • collapsed (bool) –

    If True, this menu item is collapsed by default.

selected()

Check current URL against this item.

conjunto.menu.Menu

Represents a named menu during a request.

Usually it is used in Django templates by calling menus.<name> which then will return all MenuItems with a matching "menu" name attribute. Therefore, Menu will be instantiated by a context_processor, so that the menu variable in the template

<ul>
{% for item in menus.user %}
    <li><a href="{{item.url}}">{{ item.title }}</a></li>
{% endfor %}
</ul>

__getitem__(item)

Returns filtered out menu items with the given '.menu' name.

conjunto.menu.MenuItemInterfaceMixin

A mixin that provides common functionality for menu items or action buttons etc.

Attributes:
  • title (str) –

    the (translatable) title that should be displayed in the menu.

  • menu (str) –

    The menu name where this MenuItem should be rendered. Can be any string. This menuitem is then found in templates under the menu.<this-menu-attr> menu. If you don't specify a menu, "main" is used.

  • weight (int) –

    The "weight" of the menu. The higher the weight, the more it "sinks" down in the menu. Default: 0

  • icon (str) –

    The (Bootstrap) icon name to display, if the menu shows icons.

  • slug (str) –

    The slug (machine name) of the item, used for css classes etc. If not provided, it is auto-generated from the title.

  • view_name (str) –

    The name of the view (in the form 'module:view-name', like in urls.py) under which this menu item should show up. If left empty, the menu item will show up under all views.

  • required_permissions (list) –

    The permissions necessary to view this menu item.

    Warning

    this has nothing to do with the required permissions to call the URL that this MenuItem points to. You must make sure for yourself that the required permissions are checked correctly at the view.

  • disabled (bool) –

    bool = False

  • visible (bool) –

    If True, this item is visible.

  • check (bool) –

    A callable that returns True if the item should be displayed, False otherwise.

__getattr__(item)

For all attrs that are requested in the template and are not defined in the class, don't produce an error, just return an empty string.

children()

Returns an iterable of all children of this menu item.

filter(name) classmethod

Filter the menu items by the 'menu' key name.

has_children()

Returns True if this menu item has children, False otherwise.

has_parent()

Returns True if this menu item has a parent, False otherwise.