<s> from __future__ import unicode_literals <EOL> from django . contrib . admin import FieldListFilter <EOL> try : <EOL> from django . contrib . admin . utils import prepare_lookup_value <EOL> except ImportError : <EOL> from django . contrib . admin . util import prepare_lookup_value <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> class NullFieldListFilter ( FieldListFilter ) : <EOL> def __init__ ( self , field , request , params , model , model_admin , field_path ) : <EOL> self . lookup_kwarg = '<STR_LIT>' . format ( field_path ) <EOL> super ( NullFieldListFilter , self ) . __init__ ( field , request , params , model , model_admin , field_path ) <EOL> lookup_choices = self . lookups ( request , model_admin ) <EOL> self . lookup_choices = ( ) if lookup_choices is None else list ( lookup_choices ) <EOL> def expected_parameters ( self ) : <EOL> return [ self . lookup_kwarg ] <EOL> def value ( self ) : <EOL> return self . used_parameters . get ( self . lookup_kwarg , None ) <EOL> def lookups ( self , request , model_admin ) : <EOL> return ( <EOL> ( '<STR_LIT:1>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT:0>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> def choices ( self , cl ) : <EOL> yield { <EOL> '<STR_LIT>' : self . value ( ) is None , <EOL> '<STR_LIT>' : cl . get_query_string ( { } , [ self . lookup_kwarg ] ) , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> for lookup , title in self . lookup_choices : <EOL> yield { <EOL> '<STR_LIT>' : self . value ( ) == prepare_lookup_value ( self . lookup_kwarg , lookup ) , <EOL> '<STR_LIT>' : cl . get_query_string ( { <EOL> self . lookup_kwarg : lookup , <EOL> } , [ ] ) , <EOL> '<STR_LIT>' : title , <EOL> } <EOL> def queryset ( self , request , queryset ) : <EOL> if self . value ( ) is not None : <EOL> kwargs = { self . lookup_kwarg : self . value ( ) } <EOL> return queryset . filter ( ** kwargs ) <EOL> return queryset <EOL> class NotNullFieldListFilter ( NullFieldListFilter ) : <EOL> def lookups ( self , request , model_admin ) : <EOL> return ( <EOL> ( '<STR_LIT:0>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT:1>' , _ ( '<STR_LIT>' ) ) , <EOL> ) </s>
