<s> from datetime import date <EOL> from django . utils . dateformat import DateFormat <EOL> from django . utils . formats import date_format <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from wagtail . contrib . wagtailroutablepage . models import RoutablePageMixin , route <EOL> from wagtail . wagtailcore . models import Page <EOL> from wagtail . wagtailsearch . models import Query <EOL> class BlogRoutes ( RoutablePageMixin ) : <EOL> @ route ( r'<STR_LIT>' ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_by_date ( self , request , year , month = None , day = None , * args , ** kwargs ) : <EOL> self . entries = self . get_entries ( ) . filter ( date__year = year ) <EOL> self . search_type = _ ( '<STR_LIT:date>' ) <EOL> self . search_term = year <EOL> if month : <EOL> self . entries = self . entries . filter ( date__month = month ) <EOL> df = DateFormat ( date ( int ( year ) , int ( month ) , <NUM_LIT:1> ) ) <EOL> self . search_term = df . format ( '<STR_LIT>' ) <EOL> if day : <EOL> self . entries = self . entries . filter ( date__day = day ) <EOL> self . search_term = date_format ( date ( int ( year ) , int ( month ) , int ( day ) ) ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_by_tag ( self , request , tag , * args , ** kwargs ) : <EOL> self . search_type = _ ( '<STR_LIT>' ) <EOL> self . search_term = tag <EOL> self . entries = self . get_entries ( ) . filter ( tags__slug = tag ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_by_category ( self , request , category , * args , ** kwargs ) : <EOL> self . search_type = _ ( '<STR_LIT>' ) <EOL> self . search_term = category <EOL> self . entries = self . get_entries ( ) . filter ( entry_categories__category__slug = category ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_by_author ( self , request , author , * args , ** kwargs ) : <EOL> self . search_type = _ ( '<STR_LIT>' ) <EOL> self . search_term = author <EOL> self . entries = self . get_entries ( ) . filter ( owner__username = author ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_search ( self , request , * args , ** kwargs ) : <EOL> search_query = request . GET . get ( '<STR_LIT:q>' , None ) <EOL> self . entries = self . get_entries ( ) <EOL> if search_query : <EOL> self . entries = self . entries . search ( search_query ) <EOL> self . search_term = search_query <EOL> self . search_type = _ ( '<STR_LIT>' ) <EOL> Query . get ( search_query ) . add_hit ( ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) <EOL> @ route ( r'<STR_LIT>' ) <EOL> def entries_list ( self , request , * args , ** kwargs ) : <EOL> self . entries = self . get_entries ( ) <EOL> return Page . serve ( self , request , * args , ** kwargs ) </s>
