<s> from __future__ import unicode_literals <EOL> from django . views . decorators . cache import never_cache <EOL> from rest_framework import generics , mixins <EOL> from rest_framework . renderers import BrowsableAPIRenderer <EOL> from rest_framework . exceptions import PermissionDenied <EOL> from shop . rest . serializers import OrderListSerializer , OrderDetailSerializer <EOL> from shop . rest . money import JSONRenderer <EOL> from shop . rest . renderers import CMSPageRenderer <EOL> from shop . models . order import OrderModel <EOL> class OrderView ( mixins . ListModelMixin , mixins . RetrieveModelMixin , generics . GenericAPIView ) : <EOL> """<STR_LIT>""" <EOL> renderer_classes = ( CMSPageRenderer , JSONRenderer , BrowsableAPIRenderer ) <EOL> many = True <EOL> def get_queryset ( self ) : <EOL> return OrderModel . objects . filter_from_request ( self . request ) <EOL> def get_serializer_class ( self ) : <EOL> if self . many : <EOL> return OrderListSerializer <EOL> return OrderDetailSerializer <EOL> def get_renderer_context ( self ) : <EOL> renderer_context = super ( OrderView , self ) . get_renderer_context ( ) <EOL> if self . request . accepted_renderer . format == '<STR_LIT:html>' : <EOL> renderer_context [ '<STR_LIT>' ] = self . many <EOL> if self . many is False : <EOL> try : <EOL> renderer_context [ '<STR_LIT>' ] = self . get_object ( ) . get_number ( ) <EOL> except ( AttributeError , PermissionDenied ) : <EOL> pass <EOL> return renderer_context <EOL> def get_template_names ( self ) : <EOL> return [ self . request . current_page . get_template ( ) ] <EOL> def get_object ( self ) : <EOL> if self . lookup_field not in self . kwargs : <EOL> return self . get_queryset ( ) . first ( ) <EOL> return super ( OrderView , self ) . get_object ( ) <EOL> @ never_cache <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if self . is_last ( ) : <EOL> self . many = False <EOL> if self . many : <EOL> return self . list ( request , * args , ** kwargs ) <EOL> return self . retrieve ( request , * args , ** kwargs ) <EOL> def is_last ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request . current_page . reverse_id == '<STR_LIT>' </s>
