From 06cac195f012b089d01813e6779aa5c1d0320d49 Mon Sep 17 00:00:00 2001 From: Jason Bau Date: Sat, 28 Sep 2013 00:30:47 -0700 Subject: [PATCH] make ENABLE_SHOPPING_CART truly optional course_about was throwing 500s if ENABLE_SHOPPING_CART=False --- lms/djangoapps/courseware/views.py | 3 +- lms/templates/courseware/course_about.html | 52 ++++++++++++---------- lms/templates/navigation.html | 2 +- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 4488b510d0..c5489d3b30 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -609,7 +609,8 @@ def course_about(request, course_id): registration_price = 0 in_cart = False reg_then_add_to_cart_link = "" - if settings.MITX_FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION'): + if (settings.MITX_FEATURES.get('ENABLE_SHOPPING_CART') and + settings.MITX_FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION')): registration_price = CourseMode.min_course_price_for_currency(course_id, settings.PAID_COURSE_REGISTRATION_CURRENCY[0]) if request.user.is_authenticated(): diff --git a/lms/templates/courseware/course_about.html b/lms/templates/courseware/course_about.html index e63003b3ee..382dbf4660 100644 --- a/lms/templates/courseware/course_about.html +++ b/lms/templates/courseware/course_about.html @@ -3,8 +3,12 @@ from django.core.urlresolvers import reverse from courseware.courses import course_image_url, get_course_about_section from courseware.access import has_access + from django.conf import settings - cart_link = reverse('shoppingcart.views.show_cart') + if settings.MITX_FEATURES.get('ENABLE_SHOPPING_CART'): + cart_link = reverse('shoppingcart.views.show_cart') + else: + cart_link = "" %> <%namespace name='static' file='../static_content.html'/> @@ -26,29 +30,31 @@ $("#class_enroll_form").submit(); event.preventDefault(); }); - add_course_complete_handler = function(jqXHR, textStatus) { - if (jqXHR.status == 200) { - location.href = "${cart_link}"; - } - if (jqXHR.status == 400) { - $("#register_error") - .html(jqXHR.responseText ? jqXHR.responseText : "${_('An error occurred. Please try again later.')}") - .css("display", "block"); - } - else if (jqXHR.status == 403) { - location.href = "${reg_then_add_to_cart_link}"; - } - }; - $("#add_to_cart_post").click(function(event){ - $.ajax({ - url: "${reverse('add_course_to_cart', args=[course.id])}", - type: "POST", - /* Rant: HAD TO USE COMPLETE B/C PROMISE.DONE FOR SOME REASON DOES NOT WORK ON THIS PAGE. */ - complete: add_course_complete_handler - }) - event.preventDefault(); - }); + % if settings.MITX_FEATURES.get('ENABLE_SHOPPING_CART') and settings.MITX_FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION'): + add_course_complete_handler = function(jqXHR, textStatus) { + if (jqXHR.status == 200) { + location.href = "${cart_link}"; + } + if (jqXHR.status == 400) { + $("#register_error") + .html(jqXHR.responseText ? jqXHR.responseText : "${_('An error occurred. Please try again later.')}") + .css("display", "block"); + } + else if (jqXHR.status == 403) { + location.href = "${reg_then_add_to_cart_link}"; + } + }; + $("#add_to_cart_post").click(function(event){ + $.ajax({ + url: "${reverse('add_course_to_cart', args=[course.id])}", + type: "POST", + /* Rant: HAD TO USE COMPLETE B/C PROMISE.DONE FOR SOME REASON DOES NOT WORK ON THIS PAGE. */ + complete: add_course_complete_handler + }) + event.preventDefault(); + }); + % endif ## making the conditional around this entire JS block for sanity %if settings.MITX_FEATURES.get('RESTRICT_ENROLL_BY_REG_METHOD') and course.enrollment_domain: diff --git a/lms/templates/navigation.html b/lms/templates/navigation.html index 4182696eb1..e2e1d9d664 100644 --- a/lms/templates/navigation.html +++ b/lms/templates/navigation.html @@ -84,7 +84,7 @@ site_status_msg = get_site_status_msg(course_id) % if settings.MITX_FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION') and \ - settings.MITX_FEATURES['ENABLE_SHOPPING_CART'] and \ + settings.MITX_FEATURES.get('ENABLE_SHOPPING_CART') and \ shoppingcart.models.Order.user_cart_has_items(user):