From 826ef28b4de98aa4800b8cf137ba9dd577aad0ae Mon Sep 17 00:00:00 2001 From: Matthew Piatetsky Date: Thu, 8 Feb 2018 10:25:52 -0500 Subject: [PATCH 1/2] handle exceptions and create the necessary html in optimizely --- common/djangoapps/student/views/dashboard.py | 44 ++++++++++++------- .../dashboard/_dashboard_course_listing.html | 16 ------- themes/edx.org/lms/templates/dashboard.html | 2 +- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py index f4862d60b3..1a6f29d28b 100644 --- a/common/djangoapps/student/views/dashboard.py +++ b/common/djangoapps/student/views/dashboard.py @@ -585,25 +585,35 @@ def student_dashboard(request): ecommerce_service = EcommerceService() inverted_programs = meter.invert_programs() - urls, program_data = {}, {} + urls, programs_data = {}, {} bundles_on_dashboard_flag = WaffleFlag(WaffleFlagNamespace(name=u'student.experiments'), u'bundles_on_dashboard') if bundles_on_dashboard_flag.is_enabled(): - programs_data = meter.programs - - if programs_data and inverted_programs and inverted_programs.values(): - program_uuid = inverted_programs.values()[0][0]['uuid'] - meter.programs = [get_programs(request.site, uuid=program_uuid)] - program_data = meter.programs[0] - program_data = ProgramDataExtender(program_data, request.user).extend() - - skus = program_data.get('skus') - - urls = { - 'commerce_api_url': reverse('commerce_api:v0:baskets:create'), - 'buy_button_url': ecommerce_service.get_checkout_page_url(*skus) - } - urls['completeProgramURL'] = urls['buy_button_url'] + '&bundle=' + program_data.get('uuid') + programs_data = {} + if inverted_programs and inverted_programs.items(): + for program in inverted_programs.values(): + try: + program_uuid = program[0]['uuid'] + program_data = get_programs(request.site, uuid=program_uuid) + program_data = ProgramDataExtender(program_data, request.user).extend() + skus = program_data.get('skus') + program_data['completeProgramURL'] = ecommerce_service.get_checkout_page_url(*skus) + '&bundle=' + program_data.get('uuid') + price_string = '' + import pdb; pdb.set_trace() + is_discounted = program_data.get('discount_data', {}).get('total_incl_tax_excl_discounts') + if is_discounted: + price_string += '' + '( {price}'.format(price=is_discounted) + '' + price = program_data.get('full_program_price') + if price: + price_string += ' ${price} USD ) '.format(price=price) + program_data['priceString'] = price_string + programs_data[program_uuid] = program_data + except: + pass + try: + programs_data = json.dumps(programs_data) + except: + programs_data = {} # Construct a dictionary of course mode information # used to render the course list. We re-use the course modes dict @@ -709,7 +719,7 @@ def student_dashboard(request): context = { 'urls': urls, - 'program_data': program_data, + 'programs_data': programs_data, 'enterprise_message': enterprise_message, 'consent_required_courses': consent_required_courses, 'enterprise_customer_name': enterprise_customer_name, diff --git a/lms/templates/dashboard/_dashboard_course_listing.html b/lms/templates/dashboard/_dashboard_course_listing.html index 68d4b3aeb0..2d900e2019 100644 --- a/lms/templates/dashboard/_dashboard_course_listing.html +++ b/lms/templates/dashboard/_dashboard_course_listing.html @@ -335,22 +335,6 @@ from util.course import get_link_for_about_page, get_encoded_course_sharing_utm_ % endfor -
- % if program_data.get('is_learner_eligible_for_one_click_purchase'): - - % endif -
% endif diff --git a/themes/edx.org/lms/templates/dashboard.html b/themes/edx.org/lms/templates/dashboard.html index fb7155d905..3ba1934de0 100644 --- a/themes/edx.org/lms/templates/dashboard.html +++ b/themes/edx.org/lms/templates/dashboard.html @@ -146,7 +146,7 @@ from student.models import CourseEnrollment

${_("My Courses")}

% if len(course_entitlements + course_enrollments) > 0: -