@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
@require_level('staff')
def get_coupon_codes(request, course_id):
 course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
 coupons = Coupon.objects.filter(course_id=course_id)
 query_features = [('code', _('Coupon Code')), ('course_id', _('Course Id')), ('percentage_discount', _('% Discount')), ('description', _('Description')), ('expiration_date', _('Expiration Date')), ('is_active', _('Is Active')), ('code_redeemed_count', _('Code Redeemed Count')), ('total_discounted_seats', _('Total Discounted Seats')), ('total_discounted_amount', _('Total Discounted Amount'))]
 db_columns = [x[0] for x in query_features]
 csv_columns = [x[1] for x in query_features]
 coupons_list = instructor_analytics.basic.coupon_codes_features(db_columns, coupons, course_id)
 (__, data_rows) = instructor_analytics.csvs.format_dictlist(coupons_list, db_columns)
 return instructor_analytics.csvs.create_csv_response('Coupons.csv', csv_columns, data_rows)

@ ensure_csrf_cookie @ cache_control ( no_cache = True , no_store = True , must_revalidate = True ) @ require_level ( 'staff' ) def get_coupon_codes ( request , course_id ) : course_id = SlashSeparatedCourseKey . from_deprecated_string ( course_id ) coupons = Coupon . objects . filter ( course_id = course_id ) query_features = [ ( 'code' , _ ( 'Coupon Code' ) ) , ( 'course_id' , _ ( 'Course Id' ) ) , ( 'percentage_discount' , _ ( '% Discount' ) ) , ( 'description' , _ ( 'Description' ) ) , ( 'expiration_date' , _ ( 'Expiration Date' ) ) , ( 'is_active' , _ ( 'Is Active' ) ) , ( 'code_redeemed_count' , _ ( 'Code Redeemed Count' ) ) , ( 'total_discounted_seats' , _ ( 'Total Discounted Seats' ) ) , ( 'total_discounted_amount' , _ ( 'Total Discounted Amount' ) ) ] db_columns = [ x [ 0 ] for x in query_features ] csv_columns = [ x [ 1 ] for x in query_features ] coupons_list = instructor_analytics . basic . coupon_codes_features ( db_columns , coupons , course_id ) ( __ , data_rows ) = instructor_analytics . csvs . format_dictlist ( coupons_list , db_columns ) return instructor_analytics . csvs . create_csv_response ( 'Coupons.csv' , csv_columns , data_rows )
respond with csv which contains a summary of all active coupons .