def getobjectid(obj):
    """Try to get the id of an object or dict"""
    try:
        return obj.id
    except AttributeError:
        try:
            return obj.get('id', obj.get('_id', None))
        except AttributeError:
            pass
    return obj