def get_filter(doctype, f):
 from frappe.model import default_fields, optional_fields
 if isinstance(f, dict):
  (key, value) = f.items()[0]
  f = make_filter_tuple(doctype, key, value)
 if (not isinstance(f, (list, tuple))):
  frappe.throw(u'Filter must be a tuple or list (in a list)')
 if (len(f) == 3):
  f = (doctype, f[0], f[1], f[2])
 elif (len(f) != 4):
  frappe.throw(u'Filter must have 4 values (doctype, fieldname, operator, value): {0}'.format(str(f)))
 f = frappe._dict(doctype=f[0], fieldname=f[1], operator=f[2], value=f[3])
 if (not f.operator):
  f.operator = u'='
 valid_operators = (u'=', u'!=', u'>', u'<', u'>=', u'<=', u'like', u'not like', u'in', u'not in', u'Between')
 if (f.operator not in valid_operators):
  frappe.throw(u'Operator must be one of {0}'.format(u', '.join(valid_operators)))
 if (f.doctype and (f.fieldname not in (default_fields + optional_fields))):
  meta = frappe.get_meta(f.doctype)
  if (not meta.has_field(f.fieldname)):
   for df in meta.get_table_fields():
    if frappe.get_meta(df.options).has_field(f.fieldname):
     f.doctype = df.options
     break
 return f

def get_filter ( doctype , f ) : from frappe . model import default_fields , optional_fields if isinstance ( f , dict ) : ( key , value ) = f . items ( ) [ 0 ] f = make_filter_tuple ( doctype , key , value ) if ( not isinstance ( f , ( list , tuple ) ) ) : frappe . throw ( u'Filter must be a tuple or list (in a list)' ) if ( len ( f ) == 3 ) : f = ( doctype , f [ 0 ] , f [ 1 ] , f [ 2 ] ) elif ( len ( f ) != 4 ) : frappe . throw ( u'Filter must have 4 values (doctype, fieldname, operator, value): {0}' . format ( str ( f ) ) ) f = frappe . _dict ( doctype = f [ 0 ] , fieldname = f [ 1 ] , operator = f [ 2 ] , value = f [ 3 ] ) if ( not f . operator ) : f . operator = u'=' valid_operators = ( u'=' , u'!=' , u'>' , u'<' , u'>=' , u'<=' , u'like' , u'not like' , u'in' , u'not in' , u'Between' ) if ( f . operator not in valid_operators ) : frappe . throw ( u'Operator must be one of {0}' . format ( u', ' . join ( valid_operators ) ) ) if ( f . doctype and ( f . fieldname not in ( default_fields + optional_fields ) ) ) : meta = frappe . get_meta ( f . doctype ) if ( not meta . has_field ( f . fieldname ) ) : for df in meta . get_table_fields ( ) : if frappe . get_meta ( df . options ) . has_field ( f . fieldname ) : f . doctype = df . options break return f
resolves f to a filter instance .