Merge pull request #24670 from edx/mikix/outline-offer-html
AA-278: Add offer html to the course-home API
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'''<div class="first-purchase-offer-banner" role="note">
|
||||
<span class="first-purchase-offer-banner-bold">
|
||||
Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}]</span>
|
||||
<span class="first-purchase-offer-banner-bold"><b>
|
||||
Upgrade by {discount_expiration_date} and save {percentage}% [{strikeout_price}]</b></span>
|
||||
<br>Use code <b>EDXWELCOME</b> at checkout! <a id="welcome" href="{upgrade_link}">Upgrade Now</a>
|
||||
</div>'''.format(
|
||||
discount_expiration_date=discount_expiration_date,
|
||||
|
||||
@@ -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"<span class='sr'>"
|
||||
u"<span class='sr-only'>"
|
||||
u"Original price: <span class='price original'>{original_price}</span>, discount price: "
|
||||
u"</span>"
|
||||
u"<span class='price discount'>{discount_price}</span> "
|
||||
|
||||
@@ -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("<span class='sr'>"),
|
||||
s_sr=HTML("<span class='sr-only'>"),
|
||||
s_op=HTML("<span class='price original'>"),
|
||||
e_p=HTML("</span>"),
|
||||
e_sr=HTML("</span>"),
|
||||
@@ -133,11 +133,11 @@ def generate_offer_html(user, course):
|
||||
br=HTML('<br>'),
|
||||
banner_open=HTML(
|
||||
'<div class="first-purchase-offer-banner" role="note">'
|
||||
'<span class="first-purchase-offer-banner-bold">'
|
||||
'<span class="first-purchase-offer-banner-bold"><b>'
|
||||
),
|
||||
discount_expiration_date=discount_expiration_date.strftime(u'%B %d'),
|
||||
percentage=discount_percentage(course),
|
||||
span_close=HTML('</span>'),
|
||||
span_close=HTML('</b></span>'),
|
||||
div_close=HTML('</div>'),
|
||||
strikeout_price=HTML(format_strikeout_price(user, course, check_for_discount=False)[0])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user