<s> from django . shortcuts import render_to_response <EOL> from django . template . context import RequestContext <EOL> from django . core . paginator import Paginator <EOL> from django . http import Http404 , HttpResponseServerError <EOL> from haystack . query import SearchQuerySet <EOL> from django . conf import settings <EOL> import datetime , time <EOL> RESULTS_PER_PAGE = getattr ( settings , '<STR_LIT>' , <NUM_LIT:20> ) <EOL> def tumble ( request , date_field = '<STR_LIT>' , template_name = '<STR_LIT>' , searchqueryset = None , <EOL> paginate_by = RESULTS_PER_PAGE , context_class = RequestContext , extra_context = { } ) : <EOL> """<STR_LIT>""" <EOL> if not searchqueryset : <EOL> searchqueryset = SearchQuerySet ( ) . all ( ) <EOL> things = searchqueryset . order_by ( '<STR_LIT>' % date_field ) <EOL> paginator = Paginator ( things , paginate_by ) <EOL> try : <EOL> page = paginator . page ( int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) ) <EOL> except ValueError : <EOL> raise Http404 <EOL> context_dict = { <EOL> '<STR_LIT>' : page , <EOL> '<STR_LIT>' : paginator , <EOL> } <EOL> context_dict . update ( extra_context ) <EOL> return render_to_response ( template_name , context_dict , context_instance = context_class ( request ) ) <EOL> def archive_year ( request , year , searchqueryset = None , date_field = '<STR_LIT>' , template_name = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not searchqueryset : <EOL> searchqueryset = SearchQuerySet ( ) . all ( ) <EOL> try : <EOL> year = int ( year ) <EOL> except ValueError : <EOL> return HttpResponseServerError ( u'<STR_LIT>' ) <EOL> lookup_kwargs = { <EOL> '<STR_LIT>' % date_field : datetime . datetime ( year , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> '<STR_LIT>' % date_field : datetime . datetime ( year , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> } <EOL> return tumble ( request , searchqueryset = searchqueryset . filter ( ** lookup_kwargs ) , template_name = template_name , ** kwargs ) <EOL> def archive_month ( request , year , month , searchqueryset = None , date_field = '<STR_LIT>' , month_format = '<STR_LIT>' , <EOL> template_name = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not searchqueryset : <EOL> searchqueryset = SearchQuerySet ( ) . all ( ) <EOL> try : <EOL> tt = time . strptime ( "<STR_LIT>" % ( year , month ) , '<STR_LIT>' % ( '<STR_LIT>' , month_format ) ) <EOL> date = datetime . date ( * tt [ : <NUM_LIT:3> ] ) <EOL> except ValueError : <EOL> raise Http404 <EOL> now = datetime . datetime . now ( ) <EOL> first_day = date . replace ( day = <NUM_LIT:1> ) <EOL> if first_day . month == <NUM_LIT:12> : <EOL> last_day = first_day . replace ( year = first_day . year + <NUM_LIT:1> , month = <NUM_LIT:1> ) <EOL> else : <EOL> last_day = first_day . replace ( month = first_day . month + <NUM_LIT:1> ) <EOL> lookup_kwargs = { <EOL> '<STR_LIT>' % date_field : first_day , <EOL> '<STR_LIT>' % date_field : last_day , <EOL> } <EOL> return tumble ( request , searchqueryset = searchqueryset . filter ( ** lookup_kwargs ) , template_name = template_name , ** kwargs ) <EOL> def archive_day ( request , year , month , day , searchqueryset = None , date_field = '<STR_LIT>' , month_format = '<STR_LIT>' , day_format = '<STR_LIT>' , <EOL> template_name = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not searchqueryset : <EOL> searchqueryset = SearchQuerySet ( ) . all ( ) <EOL> try : <EOL> tt = time . strptime ( '<STR_LIT>' % ( year , month , day ) , <EOL> '<STR_LIT>' % ( '<STR_LIT>' , month_format , day_format ) ) <EOL> date = datetime . date ( * tt [ : <NUM_LIT:3> ] ) <EOL> except ValueError : <EOL> raise Http404 <EOL> lookup_kwargs = { <EOL> '<STR_LIT>' % date_field : datetime . datetime . combine ( date , datetime . time . min ) , <EOL> '<STR_LIT>' % date_field : datetime . datetime . combine ( date , datetime . time . max ) <EOL> } <EOL> return tumble ( request , searchqueryset = searchqueryset . filter ( ** lookup_kwargs ) , template_name = template_name , ** kwargs ) </s>
