I reiterate my previous comment about using parentheses to explicitly specify the order of operations for logical reduction. Balancing the different bindings between operators is hard.

I think you may want something like:
```
if (course.may_certify() and (cert_status['status'] != 'processing')) or (course.has_ended() and cert_status and not (enrollment.mode == 'audit')):