
    ^fY#              
          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 Zd Z G d d          Z G d deej                  Z G d deej                  Z G d dej        ej        e          Z G 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
    )OrderedDict)update_wrapper)
getmembers)NoReverseMatch)classonlymethod)csrf_exempt)genericsmixinsviews)MethodMapper)reversec                 V    t          | d          ot          | j        t                    S )Nmapping)hasattr
isinstancer   r   )attrs    I/var/www/html/env/lib/python3.11/site-packages/rest_framework/viewsets.py_is_extra_actionr       s#    4##N
4<(N(NN    c                 Z    | j         |k    sJ d                    | |                      | S )NzExpected 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   s     r   _check_attr_namer   $   s<    =D   	( *0T)E)E	 !  
 Kr   c                   \     e Zd ZdZedd            Z fdZd Zed             Z	d Z
 x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                     d _         d _        d _        d _        d _        st          d          D ]O}| j        v rt          d|d j        d          t           |          st           j        d|          Pdv rdv rt          d	 j        z             fd
}t          | d           t          | j
        d            |_        |_        |_        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'})`zYou tried to pass in the z& method name as a keyword argument to z(). Don't do that.z() received an invalid keyword r   suffixzO%s() received both `name` and `suffix`, which are mutually exclusive arguments.c                 
    di 	}dv rdvrd         d<   |_                                         D ]&\  }}t          ||          }t          |||           '| |_        ||_        ||_         |j        | g|R i |S )Ngethead )
action_mapitemsgetattrsetattrrequestargskwargsdispatch)
r)   r*   r+   selfmethodactionhandleractionscls
initkwargss
          r   viewz"ViewSetMixin.as_view.<locals>.viewg   s    3$$$$DF'$9$9")%.
 &DO #*--// / /!$//fg...."DLDI DK !4=:4:::6:::r   r$   )updated)assigned)r   descriptionr    detailbasename	TypeErrorhttp_method_namesr   r   r   r,   r2   r3   r1   r   )r2   r1   r3   keyr4   s   ```  r   as_viewzViewSetMixin.as_view:   s    
 
 
   	; : ; ; ;
  	( 	(Cc+++i#&33!6 7 7 7 3$$ (LLL##!' ( ( ((
 ZH
$:$: <?B|M N N N	; 	; 	; 	; 	; 	; 	;2 	tS"---- 	tS\B7777
 $4   r   c                      t                      j        |g|R i |}|j                                        }|dk    rd| _        n| 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__s        r   rB   zViewSetMixin.initialize_request   sp     -%'',WFtFFFvFF%%''Y %DKK/--f55DKr   c                     | j         d|}d}| j        r| j        j        r| j        j        j        }|r|dz   |z   }|                    d| j                   t          |g|R i |S )z>
        Reverse the action for the given `url_name`.
        -N:r)   )r9   r)   resolver_match	namespace
setdefaultr   )r-   url_namer*   r+   rI   s        r   reverse_actionzViewSetMixin.reverse_action   s     #mmmXX6	< 	>DL7 	>3=I 	2 31H)T\222x1$111&111r   c                 @    d t          | t                    D             S )zP
        Get the methods that are marked as an extra ViewSet `@action`.
        c                 4    g | ]\  }}t          ||          S r$   )r   ).0r   r.   s      r   
<listcomp>z2ViewSetMixin.get_extra_actions.<locals>.<listcomp>   s6     6 6 6 D& !.. 6 6 6r   )r   r   )r2   s    r   get_extra_actionszViewSetMixin.get_extra_actions   s.    
6 6c#3446 6 6 	6r   c                     t                      } j        |S  fd                                 D             }|D ]}	  j        d|j        } j        j        j        }|r|d|}t          | j	         j
         j                  }  j        di |j
        }|||                                <   z# t          $ r Y w xY 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                 4    g | ]}|j         j         k    |S r$   )r8   )rO   r/   r-   s     r   rP   z9ViewSetMixin.get_extra_action_url_map.<locals>.<listcomp>   s2     
 
 
}++ +++r   rF   rG   )r)   r$   )r   r8   rQ   r9   rK   r)   rH   rI   r   r*   r+   rD   get_view_namer   )r-   action_urlsr1   r/   rK   rI   urlr4   s   `       r   get_extra_action_url_mapz%ViewSetMixin.get_extra_action_url_map   s    "mm ;
 
 
 
!%!7!7!9!9
 
 

  	 	F
&*mmmV__E L7A	 ?*3))XX>Hh	4;UUU%t~666647D..0011!    s   A6B55
CC)N)r   
__module____qualname____doc__r   r=   rB   rL   classmethodrQ   rW   __classcell__)rD   s   @r   r   r   -   s        
 
 Q! Q! Q! _Q!f    2 2 2 6 6 [6      r   r   c                       e Zd ZdZdS )ViewSetzI
    The base ViewSet class does not provide any actions by default.
    Nr   rX   rY   rZ   r$   r   r   r^   r^      s          	Dr   r^   c                       e Zd ZdZdS )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.
    Nr_   r$   r   r   ra   ra      s         
 	Dr   ra   c                       e Zd ZdZdS )ReadOnlyModelViewSetzL
    A viewset that provides default `list()` and `retrieve()` actions.
    Nr_   r$   r   r   rc   rc      s          	Dr   rc   c                       e Zd ZdZdS )ModelViewSetz
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    Nr_   r$   r   r   re   re      s          	Dr   re   N)#rZ   collectionsr   	functoolsr   inspectr   django.urlsr   django.utils.decoratorsr   django.views.decorators.csrfr   rest_frameworkr	   r
   r   rest_framework.decoratorsr   rest_framework.reverser   r   r   r   APIViewr^   GenericAPIViewra   RetrieveModelMixinListModelMixinrc   CreateModelMixinUpdateModelMixinDestroyModelMixinre   r$   r   r   <module>rv      s   $ $ # # # # # $ $ $ $ $ $       & & & & & & 3 3 3 3 3 3 4 4 4 4 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 * * * * * *O O O  f f f f f f f fR	 	 	 	 	lEM 	 	 		 	 	 	 	\8#: 	 	 		 	 	 	 	64!0)	 	 	
	 
	 
	 
	 
	6*,*+(!
	 
	 
	 
	 
	r   