3

\                 @   sz   d dl mZ d dlmZ d dlmZ yd dl mZ W n  ek
rT   d dlm	Z Y nX G dd de
ZG dd	 d	eZd
S )    )reverse_lazy)feature_hidden)permissions_required)
URLPattern)RegexURLPatternc               @   sZ   e Zd ZdZdZdZdZi ZdZdddZ	dd Z
dd Zd	d
 Zdd Zedd ZdS )Applicationz
    Base application class.

    This is subclassed by each app to provide a customisable container for an
    app's views and permissions.
    Nc             K   s2   |p| j | _x |j D ]\}}t| || qW dS )zY
        kwargs:
            app_name: optionally specify the instance namespace
        N)nameapp_nameitemssetattr)selfr	   kwargskeyvalue r   1/var/www/html/oscar2019/oscar/core/application.py__init__)   s    zApplication.__init__c             C   s   g S )z7
        Return the url patterns for this app.
        r   )r   r   r   r   get_urls3   s    zApplication.get_urlsc             C   sZ   t | jrg S xF|D ]>}t|dr.| j|j t|tr| j|}|r||j|_qW |S )aW  
        Customise URL patterns.

        This method allows decorators to be wrapped around an apps URL
        patterns.

        By default, this only allows custom decorators to be specified, but you
        could override this method to do anything you want.

        Args:
            urlpatterns (list): A list of URL patterns

        url_patterns)	r   hidable_feature_namehasattrpost_process_urlsr   
isinstancer   get_url_decoratorcallback)r   urlpatternspattern	decoratorr   r   r   r   9   s    




zApplication.post_process_urlsc             C   s4   |dk	r d|kr |j dd }n|}| jj|| jS )z
        Return a list of permissions for a given URL name

        Args:
            url (str): A URL name (eg ``basket.basket``)

        Returns:
            list: A list of permission strings.
        N:   )splitpermissions_mapgetdefault_permissions)r   url	view_namer   r   r   get_permissionsY   s    zApplication.get_permissionsc             C   s"   | j |j}|rt|| jdS dS )a  
        Return the appropriate decorator for the view function with the passed
        URL name. Mainly used for access-protecting views.

        It's possible to specify:

        - no permissions necessary: use None
        - a set of permissions: use a list
        - two set of permissions (`or`): use a two-tuple of lists

        See permissions_required decorator for details
        )	login_urlN)r&   r   r   r'   )r   r   permissionsr   r   r   r   j   s    zApplication.get_url_decoratorc             C   s   | j  | j| jfS )N)r   r   r	   )r   r   r   r   urls{   s    zApplication.urls)N)__name__
__module____qualname____doc__r   r'   r   r!   r#   r   r   r   r&   r   propertyr)   r   r   r   r   r      s   

 r   c               @   s   e Zd ZedZdS )DashboardApplicationzdashboard:loginN)r*   r+   r,   r   r'   r   r   r   r   r/      s   r/   N)django.urlsr   oscar.core.loadingr   oscar.views.decoratorsr   r   ImportErrorZdjango.urls.resolversr   objectr   r/   r   r   r   r   <module>   s   r