Source code for flex_menu.menu

"""Menu and MenuItem, the tree that menus are declared with."""

import logging
from collections.abc import Callable
from typing import Optional
from urllib.parse import urlencode, urlsplit

from anytree import Node, RenderTree, search
from django.conf import settings
from django.core.handlers.wsgi import WSGIRequest
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from django.utils.functional import Promise

from .utils import get_required_url_params


[docs] def _should_log_url_failures(): """Report whether URL resolution failures should be logged. Failed URL resolution is often expected, such as a menu item hidden because the user lacks permission or an optional view isn't installed, so logging defaults to DEBUG and can be overridden with the FLEX_MENUS['log_url_failures'] setting. Returns: True if URL failures should be logged, False otherwise. """ return getattr(settings, "FLEX_MENUS", {}).get("log_url_failures", settings.DEBUG)
[docs] class _NoParentType: """Sentinel distinguishing "no parent specified" from "explicitly no parent".""" pass
_NO_PARENT = _NoParentType() # Global root menu instance root = MenuItem("DjangoFlexMenu", parent=_NO_PARENT)