
    Bh                     p    d dl mZ d dlmZ d dlmZ  G d de      Z G d de      Z G d d	e      Zd
 Z	y)    )RemovedInDjangoCMS51Warning)Modifier)	menu_poolc                   .     e Zd ZdZ fdZd Zd Z xZS )Markera_  
    Searches the current selected node and marks them.

    :param current_node: Whether the current node is selected.
    :type current_node: bool
    :param sibling: Whether siblings of the current node are marked.
    :type sibling: bool
    :param descendant: Whether descendants of the current node are marked.
    :type descendant: bool
    :param ancestor: Whether ancestors of the current node are marked.
    :type ancestor: bool

    .. note::

       This modifier is deprecated and will be removed in django CMS 4.3. The menu pool now provides the same
       functionality out of the box.
    c                 \    dd l }|j                  dt        d       t        |   |i | y )Nr   zqThe Marker modifier is deprecated and will be removed. The functionality is now provided by the menu_pool itself.   )
stacklevel)warningswarnr   super__init__)selfargskwargsr   	__class__s       ?/home/dcms/DCMS/lib/python3.12/site-packages/menus/modifiers.pyr   zMarker.__init__   s6    ''	 	 	
 	$)&)    c                    	 |s|r|S d}g }|D ]1  }	t        |	d      sd|	_        t        |	d      sd|	_        |	j                  s&|r|j                  sd|	_        |j                  |	       |	j                  r|	j                  r^|	}
|
j                  r |
j                  }
d|
_        |
j                  r |	j                  j                  D ]  }|j                  rd|_         n|D ]  }|j                  rd|_         |	j                  r| j                  |	j                         |	}|	j                  r	d|	_	        +d|	_	        4 |S )aF  
        Modifies a list of nodes based on certain conditions.

        Args:
            self: The current object of the class.
            request: The request object.
            nodes (list): A list of node objects.
            namespace: The namespace of the nodes.
            root_id: The root ID of the nodes.
            post_cut (bool): A flag indicating whether post_cut condition is met.
            breadcrumb (bool): A flag indicating whether breadcrumb condition is met.

        Returns:
            list: The modified list of nodes based on the conditions.
        N
descendantFancestorT)
hasattrr   r   parentsiblingappendselectedchildrenmark_descendantsis_leaf_node)r   requestnodes	namespaceroot_idpost_cut
breadcrumbr   
root_nodesnodenewnoder   	root_nodes                r   modifyzMarker.modify$   s0     	zL
 	)D4."'4, %;;HOO#'DL!!$'}};;"G!..")..+/( ".. $(;;#7#7 3&//.2GO3 &0 5	(1104I-5 ==))$--8}}$)!$(!9	): r   c                 V    |D ]$  }d|_         | j                  |j                         & y)z
        Mark the descendants of the given nodes.

        Args:
            nodes (list): A list of nodes to mark their descendants.

        Returns:
            None

        Raises:
            None
        TN)r   r   r   )r   r!   r'   s      r   r   zMarker.mark_descendantsX   s,      	1D"DO!!$--0	1r   )__name__
__module____qualname____doc__r   r*   r   __classcell__)r   s   @r   r   r      s    $	*2h1r   r   c                        e Zd ZdZdZd Zd Zy)Levelz 
    Marks all node levels.
    Tc                 |    |r|S |D ]2  }|j                   r|rd|_        nd|_        | j                  ||       4 |S )  
        Modify the list of nodes based on certain conditions.

        :param self: The instance of the class containing this method.
        :param request: The current request object.
        :param nodes: A list of nodes to be modified.
        :type nodes: list
        :param namespace: The namespace.
        :param root_id: The ID of the root node.
        :param post_cut: Flag indicating if the modification is happening after cutting.
        :type post_cut: bool
        :param breadcrumb: Flag indicating if the modification is happening for the breadcrumb.
        :type breadcrumb: bool
        :return: The modified list of nodes.
        :rtype: list
        r   )r   
menu_levellevelmark_levels)r   r    r!   r"   r#   r$   r%   r'   s           r   r*   zLevel.modifyp   sJ    $ L 	1D;;&'DO!"DJ  x0	1 r   c                     |j                   D ]?  }|r|j                  dz   |_        n|j                  dz   |_        | j                  ||       A y)am  
        Mark the levels of menu items.

        :param node: The root node of the menu hierarchy.
        :type node: Node
        :param post_cut: Flag indicating whether the function is called after a cut is made.
        :type post_cut: bool
        :returns: None
        :rtype: None
        :raises None: This function does not raise any exceptions.
           N)r   r5   r6   r7   )r   r'   r$   childs       r   r7   zLevel.mark_levels   sJ     ]] 	.E#'??Q#6 "jj1nUH-	.r   N)r,   r-   r.   r/   r$   r*   r7    r   r   r2   r2   j   s     H>.r   r2   c                       e Zd ZdZd Zy)AuthVisibilityzA
    Remove nodes that are login required or require a group
    c                    |s|r|S g }|D ]  }|j                   j                  dd      r|j                  j                  s2|j                   j                  dd      r(|j                  j                  s|j	                  |       y|j
                  s||j
                  j                  v s|j
                  j                  j                  |        |S )r4   visible_for_authenticatedTvisible_for_anonymous)attrgetuseris_authenticatedr   r   r   remove)	r   r    r!   r"   r#   r$   r%   finalr'   s	            r   r*   zAuthVisibility.modify   s    " zL 	2D		94@W\\EbEbYY]]#:DA',,JgJgT")=)=!=$$++D1	2 r   N)r,   r-   r.   r/   r*   r;   r   r   r=   r=      s    r   r=   c                  h    t        j                  t               t        j                  t               y)zK
    Register the AuthVisibility and Level modifiers to the menu pool.
    N)r   register_modifierr=   r2   r;   r   r   registerrI      s      /&r   N)
cms.utils.compat.warningsr   
menus.baser   menus.menu_poolr   r   r2   r=   rI   r;   r   r   <module>rM      s<    A  %a1X a1H6.H 6.rX B'r   