<s> from django . core . urlresolvers import reverse <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . template import RequestContext <EOL> from django . views . generic import ListView , DetailView <EOL> from . models import Code <EOL> from source . tags . utils import filter_queryset_by_tags <EOL> from source . utils . pagination import paginate <EOL> class CodeList ( ListView ) : <EOL> model = Code <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> self . render_json = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . tag_slugs = kwargs . get ( '<STR_LIT>' , None ) <EOL> self . tags = [ ] <EOL> return super ( CodeList , self ) . dispatch ( * args , ** kwargs ) <EOL> def get_queryset ( self ) : <EOL> queryset = Code . live_objects . prefetch_related ( '<STR_LIT>' ) <EOL> if self . tag_slugs : <EOL> queryset , self . tags = filter_queryset_by_tags ( queryset , self . tag_slugs , self . tags ) <EOL> return queryset <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( CodeList , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if self . tags : <EOL> context [ '<STR_LIT>' ] = self . tags <EOL> context [ '<STR_LIT>' ] = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . tag_slugs } ) <EOL> context [ '<STR_LIT>' ] = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . tag_slugs } ) <EOL> else : <EOL> context [ '<STR_LIT>' ] = reverse ( '<STR_LIT>' ) <EOL> context [ '<STR_LIT>' ] = reverse ( '<STR_LIT>' ) <EOL> return context <EOL> def render_to_response ( self , context ) : <EOL> if self . render_json : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in self . request . GET : <EOL> context [ '<STR_LIT>' ] = self . request . GET [ '<STR_LIT>' ] <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> context , <EOL> context_instance = RequestContext ( self . request ) , <EOL> mimetype = '<STR_LIT:application/json>' <EOL> ) <EOL> return super ( CodeList , self ) . render_to_response ( context ) <EOL> class CodeDetail ( DetailView ) : <EOL> model = Code <EOL> def get_queryset ( self ) : <EOL> queryset = Code . live_objects . prefetch_related ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return queryset </s>
