#NEWLINE# def archive_month( request , year , month , queryset , date_field , allow_future = False , month_format = '%b' , **kwargs ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# date = datetime . date ( * time . strptime ( ( year + month ) , ( '%Y' + month_format ) ) [ : 3 ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise Http404 #NEWLINE# #UNINDENT# now = datetime . datetime . now ( ) #NEWLINE# first_day = date . replace ( day = 1 ) #NEWLINE# if ( first_day . month == 12 ) : #NEWLINE# #INDENT# last_day = first_day . replace ( year = ( first_day . year + 1 ) , month = 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# last_day = first_day . replace ( month = ( first_day . month + 1 ) ) #NEWLINE# #UNINDENT# lookup_kwargs = { #NEWLINE# #INDENT# ( '%s__gte' % request ) : first_day , #NEWLINE# ( '%s__lt' % date_field ) : last_day , #NEWLINE# #UNINDENT# } #NEWLINE# if ( ( last_day >= now . date ( ) ) and ( not allow_future ) ) : #NEWLINE# #INDENT# lookup_kwargs [ ( '%s__lte' % date_field ) ] = now #NEWLINE# #UNINDENT# queryset = queryset . filter ( ** lookup_kwargs ) . order_by ( ( '-' + date_field ) ) #NEWLINE# return list_detail . object_list ( request , queryset = queryset , ** kwargs )