This `if` statement is a monster. Also, your change makes the `debug` message incorrect.

A nice cleanup might be:

    start = course.enrollment_start or datetime.min
    end = course.enrollment_end or datetime.max

    if course.invitation_only:
        debug("Deny: invitation only")
        return False

    if reg_method_ok and start < now < end:
        debug("Allow: in enrollment period")
        return True