diff --git a/lms/djangoapps/commerce/api/v0/views.py b/lms/djangoapps/commerce/api/v0/views.py index 80bb14954814..8df950f0f2bb 100644 --- a/lms/djangoapps/commerce/api/v0/views.py +++ b/lms/djangoapps/commerce/api/v0/views.py @@ -84,6 +84,7 @@ def post(self, request, *args, **kwargs): """ Attempt to create the basket and enroll the user. """ + return DetailResponse('Method not allowed', status=HTTP_406_NOT_ACCEPTABLE) user = request.user valid, course_key, error = self._is_data_valid(request) if not valid: diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 3e322f0b542a..0b73733b1406 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -82,7 +82,7 @@ from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.monitoring_utils import set_custom_metrics_for_course_key from openedx.core.djangoapps.plugin_api.views import EdxFragmentView -from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender, ProgramProgressMeter +from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, course_home_url_name @@ -100,7 +100,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem from xmodule.tabs import CourseTabList from xmodule.x_module import STUDENT_VIEW -from learner_dashboard.views import courses_count +from learner_dashboard.views import get_course_ids from ..entrance_exams import user_can_skip_entrance_exam from ..module_render import get_module, get_module_by_usage_id, get_module_for_descriptor @@ -837,10 +837,10 @@ def program_marketing(request, program_uuid): if not program_data: raise Http404 - meter = ProgramProgressMeter(request.user, uuid=program_uuid) - course_data = meter.progress(programs=[program_data], count_only=False)[0] - total_courses_count = courses_count(program_data['courses']) - not_started_courses_count = courses_count(course_data['not_started']) + course_ids = get_course_ids(program_data['courses']) + total_courses_count = len(course_ids) + + started_courses_count = CourseEnrollment.enrollments_for_user(request.user).filter(course_id__in=course_ids).count() program = ProgramMarketingDataExtender(program_data, request.user).extend() program['type_slug'] = slugify(program['type']) @@ -848,8 +848,8 @@ def program_marketing(request, program_uuid): ecommerce_service = EcommerceService() price = program.get('price', '0.00') - if price != '0.00' and not_started_courses_count < total_courses_count: - program['full_program_price'] = (float(price) / total_courses_count) * not_started_courses_count + if price != '0.00' and started_courses_count: + program['full_program_price'] = (float(price) / total_courses_count) * (total_courses_count - started_courses_count) elif price != '0.00': program['full_program_price'] = float(price) diff --git a/lms/djangoapps/learner_dashboard/views.py b/lms/djangoapps/learner_dashboard/views.py index e6622d55a86c..ff4f08d692c6 100644 --- a/lms/djangoapps/learner_dashboard/views.py +++ b/lms/djangoapps/learner_dashboard/views.py @@ -16,6 +16,8 @@ ) from openedx.core.djangoapps.programs.views import program_listing as base_program_listing from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences +from opaque_keys.edx.keys import CourseKey +from student.models import CourseEnrollment @login_required @@ -23,11 +25,11 @@ def program_listing(request): return base_program_listing(request, request.user) -def courses_count(courses): - courses_count = 0 +def get_course_ids(courses): + course_ids = [] for course in courses: - courses_count += len(set(c['key'] for c in course['course_runs'])) - return courses_count + course_ids.extend([CourseKey.from_string(c['key']) for c in course['course_runs']]) + return course_ids @login_required @@ -48,12 +50,13 @@ def program_details(request, program_uuid): course_data = meter.progress(programs=[program_data], count_only=False)[0] certificate_data = get_certificates(request.user, program_data) - total_courses_count = courses_count(program_data.pop('courses')) + course_ids = get_course_ids(program_data.pop('courses')) + total_courses_count = len(course_ids) - not_started_courses_count = courses_count(course_data['not_started']) + started_courses_count = CourseEnrollment.enrollments_for_user(request.user).filter(course_id__in=course_ids).count() - if not_started_courses_count < total_courses_count: - program_data['price'] = '%.2f' % ((float(program_data['price']) / total_courses_count) * not_started_courses_count) + if started_courses_count: + program_data['price'] = '%.2f' % ((float(program_data['price']) / total_courses_count) * (total_courses_count - started_courses_count)) urls = { 'program_listing_url': reverse('program_listing_view'), diff --git a/lms/templates/courseware/program_marketing.html b/lms/templates/courseware/program_marketing.html index 8e75e0deffc5..7cb010443a30 100644 --- a/lms/templates/courseware/program_marketing.html +++ b/lms/templates/courseware/program_marketing.html @@ -80,18 +80,20 @@