def as_int_or_none(val):
    """
    Convert int or str(int) to an integer, preserving None values and returning
    False for other types.
    """
    if val is None or isinstance(val, int):
        result = val
    elif isinstance(val, str):
        try:
            result = int(val)
        except (ValueError, TypeError):
            result = False
    else:
        result = False
    return result