@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
@require_level('staff')
@require_POST
def active_registration_codes(request, course_id):
 course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
 registration_codes_list = CourseRegistrationCode.objects.filter(course_id=course_id).order_by('invoice_item__invoice__company_name')
 company_name = request.POST['active_company_name']
 if company_name:
  registration_codes_list = registration_codes_list.filter(invoice_item__invoice__company_name=company_name)
 code_redemption_set = RegistrationCodeRedemption.objects.select_related('registration_code', 'registration_code__invoice_item__invoice').filter(registration_code__course_id=course_id)
 if code_redemption_set.exists():
  redeemed_registration_codes = [code.registration_code.code for code in code_redemption_set]
  registration_codes_list = registration_codes_list.exclude(code__in=redeemed_registration_codes)
 return registration_codes_csv('Active_Registration_Codes.csv', registration_codes_list)

@ ensure_csrf_cookie @ cache_control ( no_cache = True , no_store = True , must_revalidate = True ) @ require_level ( 'staff' ) @ require_POST def active_registration_codes ( request , course_id ) : course_id = SlashSeparatedCourseKey . from_deprecated_string ( course_id ) registration_codes_list = CourseRegistrationCode . objects . filter ( course_id = course_id ) . order_by ( 'invoice_item__invoice__company_name' ) company_name = request . POST [ 'active_company_name' ] if company_name : registration_codes_list = registration_codes_list . filter ( invoice_item__invoice__company_name = company_name ) code_redemption_set = RegistrationCodeRedemption . objects . select_related ( 'registration_code' , 'registration_code__invoice_item__invoice' ) . filter ( registration_code__course_id = course_id ) if code_redemption_set . exists ( ) : redeemed_registration_codes = [ code . registration_code . code for code in code_redemption_set ] registration_codes_list = registration_codes_list . exclude ( code__in = redeemed_registration_codes ) return registration_codes_csv ( 'Active_Registration_Codes.csv' , registration_codes_list )
respond with csv which contains a summary of all active registration codes .