#NEWLINE# def test_datefieldlistfilter( self ) : #NEWLINE# #INDENT# modeladmin = BookAdmin ( Book , site ) #NEWLINE# request = self . request_factory . get ( '/' ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__gte' : self . today , #NEWLINE# 'date_registered__lt' : self . tomorrow , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . django_book , self . djangonaut_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'Today' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , ( '?date_registered__gte=%s&date_registered__lt=%s' % ( self . today , self . tomorrow ) ) ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__gte' : self . today . replace ( day = 1 ) , #NEWLINE# 'date_registered__lt' : self . next_month , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# if ( ( self . today . year , self . today . month ) == ( self . one_week_ago . year , self . one_week_ago . month ) ) : #NEWLINE# #INDENT# self . assertEqual ( list ( queryset ) , [ self . guitar_book , self . django_book , self . djangonaut_book ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertEqual ( list ( queryset ) , [ self . django_book , self . djangonaut_book ] ) #NEWLINE# #UNINDENT# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'This month' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , ( '?date_registered__gte=%s&date_registered__lt=%s' % ( self . today . replace ( day = 1 ) , self . next_month ) ) ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__gte' : self . today . replace ( month = 1 , day = 1 ) , #NEWLINE# 'date_registered__lt' : self . next_year , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# if ( self . today . year == self . one_week_ago . year ) : #NEWLINE# #INDENT# self . assertEqual ( list ( queryset ) , [ self . guitar_book , self . django_book , self . djangonaut_book ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertEqual ( list ( queryset ) , [ self . django_book , self . djangonaut_book ] ) #NEWLINE# #UNINDENT# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'This year' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , ( '?date_registered__gte=%s&date_registered__lt=%s' % ( self . today . replace ( month = 1 , day = 1 ) , self . next_year ) ) ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__gte' : str ( self . one_week_ago ) , #NEWLINE# 'date_registered__lt' : str ( self . tomorrow ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . guitar_book , queryset . django_book , self . djangonaut_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'Past 7 days' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , ( '?date_registered__gte=%s&date_registered__lt=%s' % ( str ( self . one_week_ago ) , str ( self . tomorrow ) ) ) ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__isnull' : 'True' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( queryset . count ( ) , 1 ) #NEWLINE# self . assertEqual ( queryset [ 0 ] , self . bio_book ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'No date' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , '?date_registered__isnull=True' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'date_registered__isnull' : 'False' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Book , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( queryset . count ( ) , 3 ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . guitar_book , self . django_book , self . djangonaut_book ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ 4 ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'date registered' ) #NEWLINE# choice = select_by ( filterspec . choices ( changelist ) , 'display' , 'Has date' ) #NEWLINE# self . assertEqual ( choice [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choice [ 'query_string' ] , '?date_registered__isnull=False' )