def is_course_blocked(request, redeemed_registration_codes, course_key):
 blocked = False
 for redeemed_registration in redeemed_registration_codes:
  if redeemed_registration.invoice_item:
   if (not redeemed_registration.invoice_item.invoice.is_valid):
    blocked = True
    Optout.objects.get_or_create(user=request.user, course_id=course_key)
    log.info(u'User %s (%s) opted out of receiving emails from course %s', request.user.username, request.user.email, course_key)
    track.views.server_track(request, 'change-email1-settings', {'receive_emails': 'no', 'course': course_key.to_deprecated_string()}, page='dashboard')
    break
 return blocked

def is_course_blocked ( request , redeemed_registration_codes , course_key ) : blocked = False for redeemed_registration in redeemed_registration_codes : if redeemed_registration . invoice_item : if ( not redeemed_registration . invoice_item . invoice . is_valid ) : blocked = True Optout . objects . get_or_create ( user = request . user , course_id = course_key ) log . info ( u'User %s (%s) opted out of receiving emails from course %s' , request . user . username , request . user . email , course_key ) track . views . server_track ( request , 'change-email1-settings' , { 'receive_emails' : 'no' , 'course' : course_key . to_deprecated_string ( ) } , page = 'dashboard' ) break return blocked
checking either registration is blocked or not .