<s> from django . core . urlresolvers import reverse <EOL> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext <EOL> from django . views . generic import DetailView , ListView <EOL> from multiple . projects . models import Project , Release <EOL> class ProjectsView ( ListView ) : <EOL> queryset = Project . objects . filter ( is_active = True ) <EOL> template_name = "<STR_LIT>" <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ProjectsView , self ) . get_context_data ( ** kwargs ) <EOL> items = [ ] <EOL> for project in self . object_list : <EOL> try : <EOL> last_published_release = project . release_set . filter ( <EOL> is_active = True ) . order_by ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> continue <EOL> else : <EOL> items . append ( { "<STR_LIT>" : project , <EOL> "<STR_LIT>" : last_published_release } ) <EOL> if len ( items ) : <EOL> items . sort ( key = lambda item : item [ '<STR_LIT>' ] . release_date , <EOL> reverse = True ) <EOL> context [ '<STR_LIT>' ] = items <EOL> return context <EOL> class ProjectDetailView ( DetailView ) : <EOL> model = Project <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ProjectDetailView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = [ ] <EOL> for release in self . get_object ( ) . release_set . filter ( is_active = True ) . order_by ( "<STR_LIT>" ) : <EOL> context [ '<STR_LIT>' ] . append ( release ) <EOL> return context <EOL> class ReleaseDetailView ( DetailView ) : <EOL> model = Release <EOL> def get_object ( self , queryset = None ) : <EOL> project_pk = self . kwargs . get ( '<STR_LIT>' , None ) <EOL> release_slug = self . kwargs . get ( '<STR_LIT>' , None ) <EOL> try : <EOL> obj = Release . objects . get ( project = project_pk , slug = release_slug ) <EOL> except ObjectDoesNotExist : <EOL> raise Http404 ( _ ( "<STR_LIT>" ) ) <EOL> return obj <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ReleaseDetailView , self ) . get_context_data ( ** kwargs ) <EOL> context . update ( { '<STR_LIT>' : reverse ( '<STR_LIT>' ) } ) <EOL> return context </s>
