def _filter(data, filters, limit=None):
 out = []
 for d in data:
  add = True
  for f in filters:
   fval = filters[f]
   if (fval is True):
    fval = (u'not None', fval)
   elif (fval is False):
    fval = (u'None', fval)
   elif (not isinstance(fval, (tuple, list))):
    if (isinstance(fval, basestring) and fval.startswith(u'^')):
     fval = (u'^', fval[1:])
    else:
     fval = (u'=', fval)
   if (not frappe.compare(getattr(d, f, None), fval[0], fval[1])):
    add = False
    break
  if add:
   out.append(d)
   if (limit and ((len(out) - 1) == limit)):
    break
 return out

def _filter ( data , filters , limit = None ) : out = [ ] for d in data : add = True for f in filters : fval = filters [ f ] if ( fval is True ) : fval = ( u'not None' , fval ) elif ( fval is False ) : fval = ( u'None' , fval ) elif ( not isinstance ( fval , ( tuple , list ) ) ) : if ( isinstance ( fval , basestring ) and fval . startswith ( u'^' ) ) : fval = ( u'^' , fval [ 1 : ] ) else : fval = ( u'=' , fval ) if ( not frappe . compare ( getattr ( d , f , None ) , fval [ 0 ] , fval [ 1 ] ) ) : add = False break if add : out . append ( d ) if ( limit and ( ( len ( out ) - 1 ) == limit ) ) : break return out
pass filters as: {"key": "val" .