a
    DgK                     @   s6   d dl Z d dlmZmZ d dlmZ G dd dZdS )    N)includere_path)decorate_urlpatternsc                   @   sT   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
edd ZdS )WagtailAPIRouterz_
    A class that provides routing and cross-linking for a collection
    of API endpoints
    c                 C   s   || _ i | _d S N)url_namespace
_endpoints)selfr    r
   T/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/api/v2/router.py__init__   s    zWagtailAPIRouter.__init__c                 C   s   || j |< d S r   )r   )r	   nameclass_r
   r
   r   register_endpoint   s    z"WagtailAPIRouter.register_endpointc                 C   s0   | j  D ] \}}t||jr
||f  S q
dS )z
        Finds the endpoint in the API that represents a model

        Returns a (name, endpoint_class) tuple. Or None if an
        endpoint is not found.
        N)r   items
issubclassmodel)r	   r   r   r   r
   r
   r   get_model_endpoint   s    z#WagtailAPIRouter.get_model_endpointc                 C   s@   |  |}|r<|d |d  }}| jd | }|j||dS dS )z
        Returns a URL path (excluding scheme and hostname) to the listing
        page of a model

        Returns None if the model is not represented by any endpoints.
        r      :	namespaceN)r   r   get_model_listing_urlpath)r	   r   endpointendpoint_nameendpoint_classr   r
   r
   r   r       s    
z*WagtailAPIRouter.get_model_listing_urlpathc                 C   sB   |  |}|r>|d |d  }}| jd | }|j|||dS dS )z
        Returns a URL path (excluding scheme and hostname) to the detail
        page of an object.

        Returns None if the object is not represented by any endpoints.
        r   r   r   r   N)r   r   get_object_detail_urlpath)r	   r   pkr   r   r   r   r
   r
   r   r   0   s    
z*WagtailAPIRouter.get_object_detail_urlpathc                    s   t   fdd}|S )Nc                    s   | _  | g|R i |S r   )Zwagtailapi_router)requestargskwargsfuncr	   r
   r   wrappedA   s    z+WagtailAPIRouter.wrap_view.<locals>.wrapped)	functoolswraps)r	   r"   r#   r
   r!   r   	wrap_view@   s    zWagtailAPIRouter.wrap_viewc                 C   sT   g }| j  D ]4\}}td| dt| |f|d}|| qt|| j |S )N^/r   )r   r   r   r   get_urlpatternsappendr   r&   )r	   Zurlpatternsr   r   patternr
   r
   r   r)   H   s    
z WagtailAPIRouter.get_urlpatternsc                 C   s   |   | j| jfS )z
        A shortcut to allow quick registration of the API in a URLconf.

        Use with Django's include() function:

            path('api/', include(myapi.urls)),
        )r)   r   )r	   r
   r
   r   urlsV   s    	zWagtailAPIRouter.urlsN)__name__
__module____qualname____doc__r   r   r   r   r   r&   r)   propertyr,   r
   r
   r
   r   r      s   r   )r$   Zdjango.urlsr   r   Zwagtail.utils.urlpatternsr   r   r
   r
   r
   r   <module>   s   