diff --git a/lms/djangoapps/course_home_api/outline/v1/serializers.py b/lms/djangoapps/course_home_api/outline/v1/serializers.py index 3c54957f61..20b3be7dcf 100644 --- a/lms/djangoapps/course_home_api/outline/v1/serializers.py +++ b/lms/djangoapps/course_home_api/outline/v1/serializers.py @@ -71,4 +71,5 @@ class OutlineTabSerializer(serializers.Serializer): dates_widget = DatesWidgetSerializer() enroll_alert = EnrollAlertSerializer() handouts_html = serializers.CharField() + offer_html = serializers.CharField() welcome_message_html = serializers.CharField() diff --git a/lms/djangoapps/course_home_api/outline/v1/views.py b/lms/djangoapps/course_home_api/outline/v1/views.py index b5238c9297..63234cb19a 100644 --- a/lms/djangoapps/course_home_api/outline/v1/views.py +++ b/lms/djangoapps/course_home_api/outline/v1/views.py @@ -2,20 +2,18 @@ Outline Tab Views """ +from django.http.response import Http404 +from django.urls import reverse +from django.utils.translation import gettext as _ +from edx_django_utils import monitoring as monitoring_utils +from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication +from opaque_keys.edx.keys import CourseKey from rest_framework.decorators import api_view, authentication_classes, permission_classes from rest_framework.exceptions import APIException, ParseError from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from django.utils.translation import ugettext as _ -from edx_django_utils import monitoring as monitoring_utils -from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication -from django.http.response import Http404 -from django.urls import reverse -from django.utils.translation import ugettext as _ -from opaque_keys.edx.keys import CourseKey - from course_modes.models import CourseMode from lms.djangoapps.course_api.blocks.transformers.blocks_api import BlocksAPITransformer from lms.djangoapps.course_blocks.api import get_course_block_access_transformers, get_course_blocks @@ -28,11 +26,13 @@ from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course from lms.djangoapps.courseware.date_summary import TodaysDate from lms.djangoapps.courseware.masquerade import setup_masquerade from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.user_api.course_tag.api import get_course_tag, set_course_tag from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG, LATEST_UPDATE_FLAG from openedx.features.course_experience.course_tools import CourseToolsPluginManager from openedx.features.course_experience.views.latest_update import LatestUpdateFragmentView from openedx.features.course_experience.views.welcome_message import PREFERENCE_KEY, WelcomeMessageFragmentView +from openedx.features.discounts.utils import generate_offer_html from student.models import CourseEnrollment from xmodule.course_module import COURSE_VISIBILITY_PUBLIC from xmodule.modulestore.django import modulestore @@ -109,6 +109,7 @@ class OutlineTabView(RetrieveAPIView): reset_masquerade_data=True, ) + course_overview = CourseOverview.get_from_id(course_key) enrollment = CourseEnrollment.get_enrollment(request.user, course_key) allow_anonymous = COURSE_ENABLE_UNENROLLED_ACCESS_FLAG.is_enabled(course_key) allow_public = allow_anonymous and course.course_visibility == COURSE_VISIBILITY_PUBLIC @@ -119,6 +120,9 @@ class OutlineTabView(RetrieveAPIView): show_handouts = show_enrolled or allow_public handouts_html = get_course_info_section(request, request.user, course, 'handouts') if show_handouts else '' + # TODO: TNL-7185 Legacy: Refactor to return the offer data and format the message in the MFE + offer_html = generate_offer_html(request.user, course_overview) + welcome_message_html = None if get_course_tag(request.user, course_key, PREFERENCE_KEY) != 'False': if LATEST_UPDATE_FLAG.is_enabled(course_key): @@ -169,6 +173,7 @@ class OutlineTabView(RetrieveAPIView): 'dates_widget': dates_widget, 'enroll_alert': enroll_alert, 'handouts_html': handouts_html, + 'offer_html': offer_html, 'welcome_message_html': welcome_message_html, } context = self.get_serializer_context() diff --git a/openedx/features/course_experience/tests/views/test_course_home.py b/openedx/features/course_experience/tests/views/test_course_home.py index e4ee830928..e454812b25 100644 --- a/openedx/features/course_experience/tests/views/test_course_home.py +++ b/openedx/features/course_experience/tests/views/test_course_home.py @@ -440,8 +440,8 @@ class TestCourseHomePageAccess(CourseHomePageTestCase): discount_expiration_date = get_discount_expiration_date(user, self.course).strftime(u'%B %d') upgrade_link = verified_upgrade_deadline_link(user=user, course=self.course) bannerText = u'''
- - Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}] + + Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}]
Use code EDXWELCOME at checkout! Upgrade Now
'''.format( discount_expiration_date=discount_expiration_date, diff --git a/openedx/features/discounts/tests/test_utils.py b/openedx/features/discounts/tests/test_utils.py index e3e258f48f..0e443a372f 100644 --- a/openedx/features/discounts/tests/test_utils.py +++ b/openedx/features/discounts/tests/test_utils.py @@ -38,7 +38,7 @@ class TestStrikeoutPrice(TestCase): content, has_discount = utils.format_strikeout_price(Mock(name='user'), Mock(name='course')) assert six.text_type(content) == ( - u"" + u"" u"Original price: {original_price}, discount price: " u"" u"{discount_price} " diff --git a/openedx/features/discounts/utils.py b/openedx/features/discounts/utils.py index 0a3438b099..dcc5b3ea7d 100644 --- a/openedx/features/discounts/utils.py +++ b/openedx/features/discounts/utils.py @@ -87,7 +87,7 @@ def format_strikeout_price(user, course, base_price=None, check_for_discount=Tru )).format( original_price=original_price, formatted_discount_price=formatted_discount_price, - s_sr=HTML(""), + s_sr=HTML(""), s_op=HTML(""), e_p=HTML(""), e_sr=HTML(""), @@ -133,11 +133,11 @@ def generate_offer_html(user, course): br=HTML('
'), banner_open=HTML( '
' - '' + '' ), discount_expiration_date=discount_expiration_date.strftime(u'%B %d'), percentage=discount_percentage(course), - span_close=HTML(''), + span_close=HTML(''), div_close=HTML('
'), strikeout_price=HTML(format_strikeout_price(user, course, check_for_discount=False)[0]) )