
    Bh$                     \    d dl mZmZ d dlmZ  G d d      Z G d d      Z G d d      Zy	)
    )AnyOptional)	smart_strc                   ,    e Zd ZdZdZd Zded   fdZy)Menuz/The base class for all menu-generating classes.Nc                 b    || _         | j                  s| j                  j                  | _        yy)zx
        Initialize the Menu class.

        Args:
            renderer: The renderer associated with the menu.
        N)renderer	namespace	__class____name__selfr	   s     :/home/dcms/DCMS/lib/python3.12/site-packages/menus/base.py__init__zMenu.__init__
   s(     !~~!^^44DN     returnNavigationNodec                     t         )z
        Get a list of NavigationNode instances for the menu.

        Args:
            request: The request object.

        Returns:
            A list of NavigationNode instances.
        )NotImplementedError)r   requests     r   	get_nodeszMenu.get_nodes   s
     "!r   )r   
__module____qualname____doc__r
   r   listr    r   r   r   r      s!    9I
5
"D)9$: 
"r   r   c                       e Zd ZdZd Zd Zy)ModifierzThe base class for all menu-modifying classes. A modifier add, removes or changes
    :class:`menus.base.NavigationNode` in the list.c                     || _         y)z
        Initialize the Modifier class.

        Args:
            renderer: The renderer associated with the modifier.
        N)r	   r   s     r   r   zModifier.__init__&   s     !r   c                      y)am  
        Modify the list of nodes.

        Args:
            request: The request object.
            nodes: List of NavigationNode instances.
            namespace: The namespace for the menu.
            root_id: ID of the root node.
            post_cut: Boolean indicating post-cut status.
            breadcrumb: Boolean indicating breadcrumb status.
        Nr   )r   r   nodesr
   root_idpost_cut
breadcrumbs          r   modifyzModifier.modify/   s     	r   N)r   r   r   r   r   r%   r   r   r   r   r   #   s    7!r   r   c                      e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
ee   ed<   	 	 	 	 dd	ed
ededee   dee   deeeef      defdZd ZdefdZdefdZdedefdZded    fdZded    fdZdefdZedefd       Zy)r   a  
    Represents each node in a menu tree.

    Attributes:
        title: The title of the menu item.
        url: The URL associated with the menu item.
        id: The unique ID of this item.
        parent_id: The ID of the parent item (optional).
        parent_namespace: The namespace of the parent (optional).
        attr: Additional information to store on this node (optional).
        visible: Indicates whether this item is visible (default is True).
    Fselectedancestor
descendantsiblingNleveltitleurlid	parent_idparent_namespaceattrvisiblec                     g | _         d| _        d| _        || _        || _        || _        || _        || _        || _        |xs i | _	        y)a  
        Initialize a NavigationNode instance.

        Args:
            title: The title of the menu item.
            url: The URL associated with the menu item.
            id: The unique ID of this item.
            parent_id: The ID of the parent item (optional).
            parent_namespace: The namespace of the parent (optional).
            attr: Additional information to store on this node (optional).
            visible: Indicates whether this item is visible (default is True).
        N)
childrenparentr
   r,   r-   r.   r/   r0   r2   r1   )r   r,   r-   r.   r/   r0   r1   r2   s           r   r   zNavigationNode.__init__R   sT    , /104(,
" 0JB		r   c                 4    dt        | j                         dS )zH
        Returns a string representation of the NavigationNode.
        z<Navigation Node: >)r   r,   r   s    r   __repr__zNavigationNode.__repr__x   s     $Idjj$9#:!<<r   r   c                     | j                   S )zj
        Returns the associated title using the naming convention of 'cms.models.pagemodel.Page'.
        )r,   r8   s    r   get_menu_titlezNavigationNode.get_menu_title~   s     zzr   c                     | j                   S )zA
        Returns the URL associated with this menu item.
        )r-   r8   s    r   get_absolute_urlzNavigationNode.get_absolute_url   s     xxr   namec                 :    | j                   j                  |d      S )z
        Retrieves a dictionary item from 'attr'. Returns None if it does not exist.

        Args:
            name: The name of the attribute.

        Returns:
            The value associated with the attribute name or None if not found.
        N)r1   get)r   r>   s     r   get_attributezNavigationNode.get_attribute   s     yy}}T4((r   c                 <    t        d | j                  D        g       S )zO
        Returns a list of all children beneath the current menu item.
        c              3   D   K   | ]  }|g|j                         z     y w)N)get_descendants).0nodes     r   	<genexpr>z1NavigationNode.get_descendants.<locals>.<genexpr>   s      NTFT1133Ns    )sumr4   r8   s    r   rD   zNavigationNode.get_descendants   s     NNPRSSr   c                 p    t        | dd      r(| j                  g| j                  j                         z   S g S )zV
        Returns a list of all parent items, excluding the current menu item.
        r5   N)getattrr5   get_ancestorsr8   s    r   rK   zNavigationNode.get_ancestors   s3     44(KK=4;;#<#<#>>>Ir   c                 @    | j                         }||j                  k(  S )z
        Checks if the node is selected based on the request path.

        Args:
            request: The request object.

        Returns:
            True if the node is selected, False otherwise.
        )r=   path)r   r   node_abs_urls      r   is_selectedzNavigationNode.is_selected   s!     ,,.w||++r   c                     | j                    S )z<
        Indicates whether the node is a leaf node.
        )r4   r8   s    r   is_leaf_nodezNavigationNode.is_leaf_node   s    
 ==  r   )NNNT)r   r   r   r   r'   bool__annotations__r(   r)   r*   r+   r   intstrr   dictr   r9   r;   r=   rA   r   rD   rK   rO   propertyrQ   r   r   r   r   r   >   s)    HdHdJGTE8C= $(*.)-$$ $ 	$
 C=$ #3-$ tCH~&$ $L= # 
)# 
)# 
)T&6!7 Tt$45 ,d , !d ! !r   r   N)typingr   r   django.utils.encodingr   r   r   r   r   r   r   <module>rZ      s+      +" ": 6y! y!r   