<s> from filters import KeywordFilter <EOL> from django . db . models import Q <EOL> class PrefixIDFilter ( KeywordFilter ) : <EOL> """<STR_LIT>""" <EOL> is_default_and = False <EOL> def __init__ ( self , name , delimiter = "<STR_LIT:->" ) : <EOL> self . prefixlookup = "<STR_LIT>" <EOL> self . delimiter = delimiter <EOL> super ( PrefixIDFilter , self ) . __init__ ( name , lookup = "<STR_LIT>" , <EOL> switchable = False ) <EOL> def filter ( self , queryset , values ) : <EOL> query_filters = Q ( ) <EOL> for value in values : <EOL> try : <EOL> prefix , sep , caseid = value . rpartition ( self . delimiter ) <EOL> except AttributeError : <EOL> prefix = None <EOL> caseid = value <EOL> if not isinstance ( caseid , int ) and not caseid . isdecimal ( ) : <EOL> prefix = value . rstrip ( self . delimiter ) <EOL> caseid = None <EOL> kwargs = { } <EOL> if prefix : <EOL> kwargs [ "<STR_LIT>" . format ( self . prefixlookup ) ] = prefix <EOL> if caseid : <EOL> kwargs [ "<STR_LIT>" . format ( self . lookup ) ] = caseid <EOL> query_filters = query_filters | Q ( ** kwargs ) <EOL> if values : <EOL> return queryset . filter ( query_filters ) . distinct ( ) <EOL> return queryset </s>
