Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix total price #557

Merged
merged 2 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lms/djangoapps/commerce/api/v0/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -837,19 +837,19 @@ 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'])
skus = program.get('skus')
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)

Expand Down
19 changes: 11 additions & 8 deletions lms/djangoapps/learner_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
)
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
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
Expand All @@ -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'),
Expand Down
24 changes: 13 additions & 11 deletions lms/templates/courseware/program_marketing.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ <h1 class="banner-title">${title}</h1>
</a>
% endif
</div>
<div class="col col-12 md-col-4 lg-col-3" id="course-trailer">
<a href="#video-modal" class="media trailer-link visible-sm" rel="leanModal">
<i class="fa fa-play-circle-o" aria-hidden="true"></i>
<span>${_('View Program Trailer')}</span>
</a>
<div class="hidden-sm">
<button href="#video-modal" class="media btn-play" rel="leanModal">
<span class="sr">Play the ${title} program video</span>
<i class="icon fa fa-2x fa-play" alt="${_('Play')}"></i>
</button>
% if video_url:
<div class="col col-12 md-col-4 lg-col-3" id="course-trailer">
<a href="#video-modal" class="media trailer-link visible-sm" rel="leanModal">
<i class="fa fa-play-circle-o" aria-hidden="true"></i>
<span>${_('View Program Trailer')}</span>
</a>
<div class="hidden-sm">
<button href="#video-modal" class="media btn-play" rel="leanModal">
<span class="sr">Play the ${title} program video</span>
<i class="icon fa fa-2x fa-play" alt="${_('Play')}"></i>
</button>
</div>
</div>
</div>
% endif
</div>
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions lms/templates/learner_dashboard/course_enroll.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
</select>
</div>
<% } %>
<div class="enroll-button">
<button type="button" class="btn-brand btn cta-primary">
<%- gettext('Enroll Now') %>
</button>
</div>
<% } else if (upcoming_course_runs.length > 0) {%>
<div class="no-action-message">
<%- gettext('Coming Soon') %>
Expand Down