'Returns true if document exists.
:param dt: DocType name.
:param dn: Document name or filter dict.'

def exists(self, dt, dn=None):

    if isinstance(dt, basestring):
        if ((dt != u'DocType') and (dt == dn)):
            return True
        try:
            return self.get_value(dt, dn, u'name')
        except:
            return None
    elif (isinstance(dt, dict) and dt.get(u'doctype')):
        try:
            conditions = []
            for d in dt:
                if (d == u'doctype'):
                    continue
                conditions.append((u'`%s`    =    "%s"' % (d, cstr(dt[d]).replace(u'"', u'"'))))
            return self.sql((u'select    name    from    `tab%s`    where    %s' % (dt[u'doctype'], u'    and    '.join(conditions))))
        except:
            return None
