3

\                 @   st   d dl Z d dlZd dlmZ d dlmZmZmZ d dlm	Z	m
Z
 d dlmZ e jdZG dd deZdd	d
ZdS )    N)ImproperlyConfigured)NoReverseMatchresolvereverse)AppNotFoundError	get_class)check_permissionszoscar.dashboardc               @   sR   e Zd ZdZdddZedd Zedd Zd	d
 Zdd Z	dd Z
dd ZdS )Nodez1
    A node in the dashboard navigation menu
    Nc             C   s.   || _ || _|| _|| _|| _|| _g | _d S )N)labeliconurl_nameurl_args
url_kwargs	access_fnchildren)selfr
   r   r   r   r   r    r   3/var/www/html/oscar2019/oscar/apps/dashboard/nav.py__init__   s    zNode.__init__c             C   s
   | j d kS )N)r   )r   r   r   r   
is_heading   s    zNode.is_headingc             C   s   t | j| j| jdS )N)argskwargs)r   r   r   r   )r   r   r   r   url    s    
zNode.urlc             C   s   | j j| d S )N)r   append)r   noder   r   r   	add_child%   s    zNode.add_childc             C   s    | j d kp| j || j| j| jS )N)r   r   r   r   )r   userr   r   r   
is_visible(   s    zNode.is_visiblec             C   sV   | j |sd S t| j| j| j| j| j| jd}x"| jD ]}|j |r6|j	| q6W |S )N)r
   r   r   r   r   r   )
r   r	   r
   r   r   r   r   r   r   r   )r   r   r   childr   r   r   filter,   s    


zNode.filterc             C   s   t | jdkS )Nr   )lenr   )r   r   r   r   has_children9   s    zNode.has_children)NNNNN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r!   r   r   r   r   r	      s    
	r	   c             C   s   t d}|dkrdS yt|||d}W n$ tk
rJ   tjdj| dS X t|jj}t	j
d|}|sl||j d d	 }yt|d
}	W n tk
r   |Y nX d|kr|jdd }
n|}
|	j|
}t| |S )a  
    Given a url_name and a user, this function tries to assess whether the
    user has the right to access the URL.
    The application instance of the view is fetched via dynamic imports,
    and those assumptions will only hold true if the standard Oscar layout
    is followed.
    Once the permissions for the view are known, the access logic used
    by the dashboard decorator is evaluated

    This function might seem costly, but a simple comparison with DTT
    did not show any change in response time
    zLPlease follow Oscar's default dashboard app layout or set a custom access_fnNT)r   r   zInvalid URL name {}Fz(dashboard[\w\.]*)\.views$r   z.appapplication:   )r   r   r   logger	exceptionformatr   funcr#   researchgroupsr   r   splitget_permissionsr   )r   r   r   r   r+   r   Zview_modulematchZapp_label_strZapp_instance	view_namepermissionsr   r   r   default_access_fn=   s.    

r6   )NN)loggingr.   django.core.exceptionsr   django.urlsr   r   r   oscar.core.loadingr   r   oscar.views.decoratorsr   	getLoggerr*   objectr	   r6   r   r   r   r   <module>   s   
0