<s> from django . views . generic . base import RedirectView <EOL> from django . views . generic . list import ListView <EOL> from django . views . generic . dates import ArchiveIndexView , MonthArchiveView , YearArchiveView <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . exceptions import PermissionDenied <EOL> from core . spaces import url_names as urln <EOL> from core . spaces . models import Space <EOL> from apps . ecidadania . news . models import Post <EOL> class RedirectArchive ( RedirectView ) : <EOL> """<STR_LIT>""" <EOL> permanent = True <EOL> def get_redirect_url ( self , ** kwargs ) : <EOL> space = self . kwargs [ '<STR_LIT>' ] <EOL> return reverse ( urln . NEWS_ARCHIVE , kwargs = { '<STR_LIT>' : space } ) <EOL> class YearlyPosts ( YearArchiveView ) : <EOL> """<STR_LIT>""" <EOL> make_object_list = True <EOL> paginate_by = <NUM_LIT:12> <EOL> date_field = '<STR_LIT>' <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> space = get_object_or_404 ( Space , url = kwargs [ '<STR_LIT>' ] ) <EOL> if request . user . has_perm ( '<STR_LIT>' , space ) : <EOL> return super ( YearlyPosts , self ) . dispatch ( request , * args , ** kwargs ) <EOL> else : <EOL> raise PermissionDenied <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> place = get_object_or_404 ( Space , url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return Post . objects . filter ( space = place . id ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( YearlyPosts , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = get_object_or_404 ( Space , <EOL> url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return context <EOL> class MonthlyPosts ( MonthArchiveView ) : <EOL> """<STR_LIT>""" <EOL> paginate_by = <NUM_LIT:12> <EOL> date_field = '<STR_LIT>' <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> space = get_object_or_404 ( Space , url = kwargs [ '<STR_LIT>' ] ) <EOL> if request . user . has_perm ( '<STR_LIT>' , space ) : <EOL> return super ( MonthlyPosts , self ) . dispatch ( request , * args , ** kwargs ) <EOL> else : <EOL> raise PermissionDenied <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> place = get_object_or_404 ( Space , url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return Post . objects . filter ( space = place . id ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( MonthlyPosts , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = get_object_or_404 ( Space , <EOL> url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return context <EOL> class ListPosts ( ArchiveIndexView ) : <EOL> """<STR_LIT>""" <EOL> date_field = '<STR_LIT>' <EOL> paginate_by = <NUM_LIT:12> <EOL> allow_empty = True <EOL> def dispatch ( self , request , * args , ** kwargs ) : <EOL> space = get_object_or_404 ( Space , url = kwargs [ '<STR_LIT>' ] ) <EOL> if request . user . has_perm ( '<STR_LIT>' , space ) : <EOL> return super ( ListPosts , self ) . dispatch ( request , * args , ** kwargs ) <EOL> else : <EOL> raise PermissionDenied <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> place = get_object_or_404 ( Space , url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return Post . objects . filter ( space = place . id ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( ListPosts , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = get_object_or_404 ( Space , <EOL> url = self . kwargs [ '<STR_LIT>' ] ) <EOL> return context </s>
