o
     ÞhL$  ã                	   @   sþ   d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ dd„ Zdd„ ZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZG dd„ dejejeƒZG dd„ dej ejej!ej"ejeƒZ#dS )a�  
ViewSets are essentially just a type of class based view, that doesn't provide
any method handlers, such as `get()`, `post()`, etc... but instead has actions,
such as `list()`, `retrieve()`, `create()`, etc...

Actions are only bound to methods at the point of instantiating the views.

    user_list = UserViewSet.as_view({'get': 'list'})
    user_detail = UserViewSet.as_view({'get': 'retrieve'})

Typically, rather than instantiate views from viewsets directly, you'll
register the viewset with a router and let the URL conf be determined
automatically.

    router = DefaultRouter()
    router.register(r'users', UserViewSet, 'user')
    urlpatterns = router.urls
é    )Úupdate_wrapper)Ú
getmembers)ÚVERSION)ÚNoReverseMatch)Úclassonlymethod)Úcsrf_exempt)ÚgenericsÚmixinsÚviews)ÚMethodMapper)Úreversec                 C   s   t | dƒo
t| jtƒS )NÚmapping)ÚhasattrÚ
isinstancer   r   )Úattr© r   úW/var/www/html/premium_crap/venv/lib/python3.10/site-packages/rest_framework/viewsets.pyÚ_is_extra_action    s   r   c                 C   s    | j |ksJ dj| |d�ƒ‚| S )NzãExpected function (`{func.__name__}`) to match its attribute name (`{name}`). If using a decorator, ensure the inner function is decorated with `functools.wraps`, or that `{func.__name__}.__name__` is otherwise set to `{name}`.©ÚfuncÚname)Ú__name__Úformatr   r   r   r   Ú_check_attr_name$   s
   ür   c                       sJ   e Zd ZdZeddd„ƒZ‡ fdd„Zdd„ Zed	d
„ ƒZ	dd„ Z
‡  ZS )ÚViewSetMixinad  
    This is the magic.

    Overrides `.as_view()` so that it takes an `actions` keyword that performs
    the binding of HTTP methods to actions on the Resource.

    For example, to create a concrete view binding the 'GET' and 'POST' methods
    to the 'list' and 'create' actions...

    view = MyViewSet.as_view({'get': 'list', 'post': 'create'})
    Nc                    sà   dˆ_ dˆ_dˆ_dˆ_dˆ_ˆ stdƒ‚ˆD ]}|ˆjv r'td|ˆjf ƒ‚tˆ|ƒs5tdˆj|f ƒ‚qdˆv rEdˆv rEtdˆj ƒ‚‡ ‡‡fdd	„}t	|ˆd
d� t	|ˆj
d
d� ˆ|_ˆ|_ˆ |_tdkrld|_t|ƒS )zä
        Because of the way class based views create a closure around the
        instantiated view, we need to totally reimplement `.as_view`,
        and slightly modify the view function that is created and returned.
        NzwThe `actions` argument must be provided when calling `.as_view()` on a ViewSet. For example `.as_view({'get': 'list'})`zUYou tried to pass in the %s method name as a keyword argument to %s(). Don't do that.z#%s() received an invalid keyword %rr   ÚsuffixzO%s() received both `name` and `suffix`, which are mutually exclusive arguments.c                    s‚   ˆdi ˆ¤Ž}dˆ v rdˆ vrˆ d ˆ d< ˆ |_ ˆ  ¡ D ]\}}t||ƒ}t|||ƒ q| |_||_||_|j| g|¢R i |¤ŽS )NÚgetÚheadr   )Ú
action_mapÚitemsÚgetattrÚsetattrÚrequestÚargsÚkwargsÚdispatch)r"   r#   r$   ÚselfÚmethodÚactionÚhandler©ÚactionsÚclsÚ
initkwargsr   r   Úviewg   s   
z"ViewSetMixin.as_view.<locals>.viewr   )Úupdated)Úassigned)é   é   F)r   Údescriptionr   ÚdetailÚbasenameÚ	TypeErrorÚhttp_method_namesr   r   r   r%   r,   r-   r+   ÚDJANGO_VERSIONÚlogin_requiredr   )r,   r+   r-   Úkeyr.   r   r*   r   Úas_view:   s<   	
þ
ÿÿÿzViewSetMixin.as_viewc                    sH   t ƒ j|g|¢R i |¤Ž}|j ¡ }|dkrd| _|S | j |¡| _|S )z[
        Set the `.action` attribute on the view, depending on the request method.
        ÚoptionsÚmetadata)ÚsuperÚinitialize_requestr'   Úlowerr(   r   r   )r&   r"   r#   r$   r'   ©Ú	__class__r   r   r?   ”   s   
ÿzViewSetMixin.initialize_requestc                 O   s^   d| j |f }d}| jr| jjr| jjj}|r|d | }| d| j¡ t|g|¢R i |¤ŽS )z>
        Reverse the action for the given `url_name`.
        ú%s-%sNú:r"   )r5   r"   Úresolver_matchÚ	namespaceÚ
setdefaultr   )r&   Úurl_namer#   r$   rF   r   r   r   Úreverse_action£   s   
zViewSetMixin.reverse_actionc                 C   s   dd„ t | tƒD ƒS )zP
        Get the methods that are marked as an extra ViewSet `@action`.
        c                 S   s   g | ]	\}}t ||ƒ‘qS r   )r   )Ú.0r   r'   r   r   r   Ú
<listcomp>¶   s    ÿz2ViewSetMixin.get_extra_actions.<locals>.<listcomp>)r   r   )r,   r   r   r   Úget_extra_actions±   s   þzViewSetMixin.get_extra_actionsc              	      sª   i }ˆ j du r	|S ‡ fdd„ˆ  ¡ D ƒ}|D ]<}z1dˆ j|jf }ˆ jjj}|r.d||f }t|ˆ jˆ j	ˆ jd�}ˆ j
di |j	¤Ž}||| ¡ < W q tyR   Y qw |S )z–
        Build a map of {names: urls} for the extra actions.

        This method will noop if `detail` was not provided as a view initkwarg.
        Nc                    s   g | ]
}|j ˆ j kr|‘qS r   )r4   )rJ   r(   ©r&   r   r   rK   Ç   s
    ÿz9ViewSetMixin.get_extra_action_url_map.<locals>.<listcomp>rC   z%s:%s)r"   r   )r4   rL   r5   rH   r"   rE   rF   r   r#   r$   rB   Úget_view_namer   )r&   Úaction_urlsr+   r(   rH   rF   Úurlr.   r   rM   r   Úget_extra_action_url_mapº   s&   

ÿ
ÿz%ViewSetMixin.get_extra_action_url_map)N)r   Ú
__module__Ú__qualname__Ú__doc__r   r;   r?   rI   ÚclassmethodrL   rQ   Ú__classcell__r   r   rA   r   r   -   s    Y
r   c                   @   ó   e Zd ZdZdS )ÚViewSetzI
    The base ViewSet class does not provide any actions by default.
    N©r   rR   rS   rT   r   r   r   r   rX   Ü   s    rX   c                   @   rW   )ÚGenericViewSetzÀ
    The GenericViewSet class does not provide any actions by default,
    but does include the base set of generic view behavior, such as
    the `get_object` and `get_queryset` methods.
    NrY   r   r   r   r   rZ   ã   s    rZ   c                   @   rW   )ÚReadOnlyModelViewSetzL
    A viewset that provides default `list()` and `retrieve()` actions.
    NrY   r   r   r   r   r[   ì   s    r[   c                   @   rW   )ÚModelViewSetz‰
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    NrY   r   r   r   r   r\   õ   s    r\   N)$rT   Ú	functoolsr   Úinspectr   Údjangor   r8   Údjango.urlsr   Údjango.utils.decoratorsr   Údjango.views.decorators.csrfr   Úrest_frameworkr   r	   r
   Úrest_framework.decoratorsr   Úrest_framework.reverser   r   r   r   ÚAPIViewrX   ÚGenericAPIViewrZ   ÚRetrieveModelMixinÚListModelMixinr[   ÚCreateModelMixinÚUpdateModelMixinÚDestroyModelMixinr\   r   r   r   r   Ú<module>   s6    	 0	þ	û