
    Nwg*#              
          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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j0                        Z G d dej4                  ej6                  e      Z G d dej:                  ej4                  ej<                  ej>                  ej6                  e      Z y)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)NoReverseMatch)classonlymethod)csrf_exempt)genericsmixinsviews)MethodMapper)reversec                 R    t        | d      xr t        | j                  t              S )Nmapping)hasattr
isinstancer   r   )attrs    N/var/www/horilla/myenv/lib/python3.12/site-packages/rest_framework/viewsets.py_is_extra_actionr      s    4#N
4<<(NN    c                 T    | j                   |k(  sJ dj                  | |             | 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   #   s9    ==D  F	( *0T)E	F 
 Kr   c                   P     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'})
    c                     d _         d _        d _        d _        d _        st        d      D ]R  }| j                  v rt        d|d j                  d      t         |      r:t         j                  d|       d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<   |_         j                         D ]  \  }}t        ||      }t        |||         | |_        ||_        ||_         |j                  | g|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>.viewf   s    $$DF'$9")%.
 &DO #*--/ /!$/fg./ #DLDI DK !4==:4:6::r   r#   )updated)assigned)r   descriptionr   detailbasename	TypeErrorhttp_method_namesr   r   r   r+   r1   r2   r0   r   )r1   r0   r2   keyr3   s   ```  r   as_viewzViewSetMixin.as_view9   s    
 
 
   : ; ;
  	(Cc+++#&!6 7 7 3$LL#!' ( (	( ZH
$: <?B||M N N	;2 	tS"- 	tS\\B7
 $4  r   c                     t        |   |g|i |}|j                  j                         }|dk(  r	d| _        |S | j
                  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   rA   zViewSetMixin.initialize_request   se     ',WFtFvF%%'Y %DK  //--f5DKr   c                    | j                   d|}d}| j                  r6| j                  j                  r | j                  j                  j                  }|r|dz   |z   }|j	                  d| j                         t        |g|i |S )z>
        Reverse the action for the given `url_name`.
        -N:r(   )r8   r(   resolver_match	namespace
setdefaultr   )r,   url_namer)   r*   rH   s        r   reverse_actionzViewSetMixin.reverse_action   sy     #mmX6	<<DLL7733==I 31H)T\\2x1$1&11r   c                 h    t        | t              D cg c]  \  }}t        ||       c}}S c c}}w )zP
        Get the methods that are marked as an extra ViewSet `@action`.
        )r   r   r   )r1   r   r-   s      r   get_extra_actionszViewSetMixin.get_extra_actions   s7     c#346 D& !. 6 	6 6s   .c                 
   i }| j                   |S | j                         D cg c]  }|j                   | j                   k(  r| }}|D ]  }	 | j                  d|j                  }| j                  j
                  j                  }|r|d|}t        || j                  | j                  | j                        } | j                  di |j                  }|||j                         <    |S c c}w # t        $ r Y w xY w)z
        Build a map of {names: urls} for the extra actions.

        This method will noop if `detail` was not provided as a view initkwarg.
        rE   rF   )r(   r#   )r7   rM   r8   rJ   r(   rG   rH   r   r)   r*   rC   get_view_namer   )r,   action_urlsr.   r0   rJ   rH   urlr3   s           r   get_extra_action_url_mapz%ViewSetMixin.get_extra_action_url_map   s     ;; "&!7!7!9
}}+ 
 

  	F
&*mmV__E LL77AA	*3X>Hh		4;;U%t~~6647D..01	 %
 " s   "C1B C66	DD)N)r   
__module____qualname____doc__r   r<   rA   rK   classmethodrM   rR   __classcell__)rC   s   @r   r   r   ,   sB    
 Q! Q!f2 6 6r   r   c                       e Zd ZdZy)ViewSetzI
    The base ViewSet class does not provide any actions by default.
    Nr   rS   rT   rU   r#   r   r   rY   rY      s     	r   rY   c                       e Zd ZdZy)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.
    NrZ   r#   r   r   r\   r\      s    
 	r   r\   c                       e Zd ZdZy)ReadOnlyModelViewSetzL
    A viewset that provides default `list()` and `retrieve()` actions.
    NrZ   r#   r   r   r^   r^      s     	r   r^   c                       e Zd ZdZy)ModelViewSetz
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    NrZ   r#   r   r   r`   r`      s     	r   r`   N)!rU   	functoolsr   inspectr   django.urlsr   django.utils.decoratorsr   django.views.decorators.csrfr   rest_frameworkr   r	   r
   rest_framework.decoratorsr   rest_framework.reverser   r   r   r   APIViewrY   GenericAPIViewr\   RetrieveModelMixinListModelMixinr^   CreateModelMixinUpdateModelMixinDestroyModelMixinr`   r#   r   r   <module>rp      s   $ %  & 3 4 2 2 2 *Of fR	lEMM 		\8#:#: 		644!00)	
	6**,,**++((!
	r   