<s> from django . views . generic . list import ListView <EOL> from django . views . generic . detail import DetailView <EOL> from . models import PressRelease , PressMention <EOL> NUM_RECENT_RELEASES = <NUM_LIT:5> <EOL> NUM_RECENT_MENTIONS = <NUM_LIT:5> <EOL> class PressReleaseListView ( ListView ) : <EOL> model = PressRelease <EOL> paginate_by = <NUM_LIT:15> <EOL> def get_queryset ( self ) : <EOL> return PressRelease . published_objects . all ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PressReleaseListView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = _recent_mentions_context ( ) <EOL> return context <EOL> class PressReleaseDetailView ( DetailView ) : <EOL> model = PressRelease <EOL> def get_queryset ( self ) : <EOL> return PressRelease . published_objects . all ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PressReleaseDetailView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = _recent_releases_context ( <EOL> context [ '<STR_LIT:object>' ] . pk ) <EOL> context [ '<STR_LIT>' ] = _recent_mentions_context ( ) <EOL> return context <EOL> class PressMentionListView ( ListView ) : <EOL> model = PressMention <EOL> paginate_by = <NUM_LIT:15> <EOL> def get_queryset ( self ) : <EOL> return PressMention . published_objects . all ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PressMentionListView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = _recent_releases_context ( ) <EOL> return context <EOL> class PressMentionDetailView ( DetailView ) : <EOL> model = PressMention <EOL> def get_queryset ( self ) : <EOL> return PressMention . published_objects . all ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PressMentionDetailView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = _recent_mentions_context ( <EOL> context [ '<STR_LIT:object>' ] . pk ) <EOL> context [ '<STR_LIT>' ] = _recent_releases_context ( ) <EOL> return context <EOL> def _recent_releases_context ( exclude_pk = None ) : <EOL> objects = PressRelease . published_objects . all ( ) <EOL> if exclude_pk is not None : <EOL> objects = objects . exclude ( pk = exclude_pk ) <EOL> return { '<STR_LIT>' : objects [ : NUM_RECENT_RELEASES ] } <EOL> def _recent_mentions_context ( exclude_pk = None ) : <EOL> objects = PressMention . objects . all ( ) <EOL> if exclude_pk is not None : <EOL> objects = objects . exclude ( pk = exclude_pk ) <EOL> return { '<STR_LIT>' : objects [ : NUM_RECENT_MENTIONS ] } </s>
