Repository URL to install this package:
|
Version:
3.6.4 ▾
|
«¬YW ã @ 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
m Z m Z Gd d d e
Z Gd d
d
e e j Z Gd d d e e
j Z Gd
d d e j e j e Z Gd 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
é )Úunicode_literals)Úupdate_wrapper)Úclassonlymethod)Úcsrf_exempt)ÚgenericsÚmixinsÚviewsc s= e Z d Z d Z e d d d Z f d d 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 _ s t d x^ D]V } | j k rP t d | j f t | s" t d j | f q" W f d d } t | d f t | j d f | _ | _ j d 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'})`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 %rc sª } | _ x9 j D]+ \ } } t | | } t | | | q" Wt | d r| t | d r| | j | _ | | _ | | _ | | _ | j
| | | S)NÚgetÚhead)Ú
action_mapÚitemsÚgetattrÚsetattrÚhasattrr
r ÚrequestÚargsÚkwargsÚdispatch)r r r ÚselfÚmethodÚactionÚhandler)ÚactionsÚclsÚ
initkwargs© úV/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/viewsets.pyÚviewE s z"ViewSetMixin.as_view.<locals>.viewÚupdatedÚassignedÚsuffix)r! Ú TypeErrorÚhttp_method_namesÚ__name__r r r r r r
r r )r r r Úkeyr r )r r r r Úas_view* s$
zViewSetMixin.as_viewc s^ t t | j | | | } | j j } | d k rE d | _ n | j j | | _ | S)zc
Set the `.action` attribute on the view,
depending on the request method.
ÚoptionsÚmetadata)Úsuperr Úinitialize_requestr Úlowerr r r
)r r r r r )Ú __class__r r r* l s zViewSetMixin.initialize_request)r$ Ú
__module__Ú__qualname__Ú__doc__r r&