def get_default_contact(doctype, name):
 out = frappe.db.sql(u'select parent,\n DCTB  DCTB  DCTB (select is_primary_contact from tabContact c where c.name = dl.parent)\n DCTB  DCTB  DCTB  DCTB as is_primary_contact\n DCTB  DCTB from\n DCTB  DCTB  DCTB `tabDynamic Link` dl\n DCTB  DCTB where\n DCTB  DCTB  DCTB dl.link_doctype=%s and\n DCTB  DCTB  DCTB dl.link_name=%s and\n DCTB  DCTB  DCTB dl.parenttype = "Contact"', (doctype, name))
 if out:
  return sorted(out, (lambda x, y: cmp(y[1], x[1])))[0][0]
 else:
  return None

def get_default_contact ( doctype , name ) : out = frappe . db . sql ( u'select parent,\n DCTB  DCTB  DCTB (select is_primary_contact from tabContact c where c.name = dl.parent)\n DCTB  DCTB  DCTB  DCTB as is_primary_contact\n DCTB  DCTB from\n DCTB  DCTB  DCTB `tabDynamic Link` dl\n DCTB  DCTB where\n DCTB  DCTB  DCTB dl.link_doctype=%s and\n DCTB  DCTB  DCTB dl.link_name=%s and\n DCTB  DCTB  DCTB dl.parenttype = "Contact"' , ( doctype , name ) ) if out : return sorted ( out , ( lambda x , y : cmp ( y [ 1 ] , x [ 1 ] ) ) ) [ 0 ] [ 0 ] else : return None
returns default contact for the given doctype .