<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from django . db . models . query import QuerySet <EOL> from django . http import Http404 <EOL> from django . shortcuts import get_object_or_404 as _get_object_or_404 <EOL> from rest_framework import mixins , views <EOL> from rest_framework . settings import api_settings <EOL> def get_object_or_404 ( queryset , * filter_args , ** filter_kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return _get_object_or_404 ( queryset , * filter_args , ** filter_kwargs ) <EOL> except ( TypeError , ValueError ) : <EOL> raise Http404 <EOL> class GenericAPIView ( views . APIView ) : <EOL> """<STR_LIT>""" <EOL> queryset = None <EOL> serializer_class = None <EOL> lookup_field = '<STR_LIT>' <EOL> lookup_url_kwarg = None <EOL> filter_backends = api_settings . DEFAULT_FILTER_BACKENDS <EOL> pagination_class = api_settings . DEFAULT_PAGINATION_CLASS <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . queryset is not None , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % self . __class__ . __name__ <EOL> ) <EOL> queryset = self . queryset <EOL> if isinstance ( queryset , QuerySet ) : <EOL> queryset = queryset . all ( ) <EOL> return queryset <EOL> def get_object ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . filter_queryset ( self . get_queryset ( ) ) <EOL> lookup_url_kwarg = self . lookup_url_kwarg or self . lookup_field <EOL> assert lookup_url_kwarg in self . kwargs , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( self . __class__ . __name__ , lookup_url_kwarg ) <EOL> ) <EOL> filter_kwargs = { self . lookup_field : self . kwargs [ lookup_url_kwarg ] } <EOL> obj = get_object_or_404 ( queryset , ** filter_kwargs ) <EOL> self . check_object_permissions ( self . request , obj ) <EOL> return obj <EOL> def get_serializer ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> serializer_class = self . get_serializer_class ( ) <EOL> kwargs [ '<STR_LIT>' ] = self . get_serializer_context ( ) <EOL> return serializer_class ( * args , ** kwargs ) <EOL> def get_serializer_class ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . serializer_class is not None , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % self . __class__ . __name__ <EOL> ) <EOL> return self . serializer_class <EOL> def get_serializer_context ( self ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> '<STR_LIT>' : self . request , <EOL> '<STR_LIT>' : self . format_kwarg , <EOL> '<STR_LIT>' : self <EOL> } <EOL> def filter_queryset ( self , queryset ) : <EOL> """<STR_LIT>""" <EOL> for backend in list ( self . filter_backends ) : <EOL> queryset = backend ( ) . filter_queryset ( self . request , queryset , self ) <EOL> return queryset <EOL> @ property <EOL> def paginator ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> if self . pagination_class is None : <EOL> self . _paginator = None <EOL> else : <EOL> self . _paginator = self . pagination_class ( ) <EOL> return self . _paginator <EOL> def paginate_queryset ( self , queryset ) : <EOL> """<STR_LIT>""" <EOL> if self . paginator is None : <EOL> return None <EOL> return self . paginator . paginate_queryset ( queryset , self . request , view = self ) <EOL> def get_paginated_response ( self , data ) : <EOL> """<STR_LIT>""" <EOL> assert self . paginator is not None <EOL> return self . paginator . get_paginated_response ( data ) <EOL> class CreateAPIView ( mixins . CreateModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> return self . create ( request , * args , ** kwargs ) <EOL> class ListAPIView ( mixins . ListModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . list ( request , * args , ** kwargs ) <EOL> class RetrieveAPIView ( mixins . RetrieveModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . retrieve ( request , * args , ** kwargs ) <EOL> class DestroyAPIView ( mixins . DestroyModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def delete ( self , request , * args , ** kwargs ) : <EOL> return self . destroy ( request , * args , ** kwargs ) <EOL> class UpdateAPIView ( mixins . UpdateModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def put ( self , request , * args , ** kwargs ) : <EOL> return self . update ( request , * args , ** kwargs ) <EOL> def patch ( self , request , * args , ** kwargs ) : <EOL> return self . partial_update ( request , * args , ** kwargs ) <EOL> class ListCreateAPIView ( mixins . ListModelMixin , <EOL> mixins . CreateModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . list ( request , * args , ** kwargs ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> return self . create ( request , * args , ** kwargs ) <EOL> class RetrieveUpdateAPIView ( mixins . RetrieveModelMixin , <EOL> mixins . UpdateModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . retrieve ( request , * args , ** kwargs ) <EOL> def put ( self , request , * args , ** kwargs ) : <EOL> return self . update ( request , * args , ** kwargs ) <EOL> def patch ( self , request , * args , ** kwargs ) : <EOL> return self . partial_update ( request , * args , ** kwargs ) <EOL> class RetrieveDestroyAPIView ( mixins . RetrieveModelMixin , <EOL> mixins . DestroyModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . retrieve ( request , * args , ** kwargs ) <EOL> def delete ( self , request , * args , ** kwargs ) : <EOL> return self . destroy ( request , * args , ** kwargs ) <EOL> class RetrieveUpdateDestroyAPIView ( mixins . RetrieveModelMixin , <EOL> mixins . UpdateModelMixin , <EOL> mixins . DestroyModelMixin , <EOL> GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return self . retrieve ( request , * args , ** kwargs ) <EOL> def put ( self , request , * args , ** kwargs ) : <EOL> return self . update ( request , * args , ** kwargs ) <EOL> def patch ( self , request , * args , ** kwargs ) : <EOL> return self . partial_update ( request , * args , ** kwargs ) <EOL> def delete ( self , request , * args , ** kwargs ) : <EOL> return self . destroy ( request , * args , ** kwargs ) </s>
