Revert "add first purchase discount to courseware (#22058)"

This reverts commit 059b619794.
This commit is contained in:
julianajlk
2019-10-21 13:57:18 -04:00
committed by GitHub
parent 059b619794
commit 98f907f23c
16 changed files with 66 additions and 111 deletions

View File

@@ -22,7 +22,6 @@ from openedx.core.djangoapps.catalog.utils import get_course_run_details
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangolib.markup import HTML
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.discounts.utils import get_first_purchase_offer_banner_fragment
from student.models import CourseEnrollment
from util.date_utils import strftime_localized
@@ -238,28 +237,3 @@ def course_expiration_wrapper(user, block, view, frag, context): # pylint: disa
course_expiration_fragment.add_fragment_resources(frag)
return course_expiration_fragment
def offer_banner_wrapper(user, block, view, frag, context): # pylint: disable=W0613
"""
A wrapper that prepends the First Purchase Discount banner if
the user hasn't upgraded yet.
"""
if block.category != "vertical":
return frag
course = CourseOverview.get_from_id(block.course_id)
offer_banner_fragment = get_first_purchase_offer_banner_fragment(user, course)
if not offer_banner_fragment:
return frag
# Course content must be escaped to render correctly due to the way the
# way the XBlock rendering works. Transforming the safe markup to unicode
# escapes correctly.
offer_banner_fragment.content = six.text_type(offer_banner_fragment.content)
offer_banner_fragment.add_content(frag.content)
offer_banner_fragment.add_fragment_resources(frag)
return offer_banner_fragment

View File

@@ -413,8 +413,8 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
)
self.assertRedirects(response, expected_url)
@mock.patch('openedx.features.discounts.utils.discount_percentage')
@mock.patch('openedx.features.discounts.utils.can_receive_discount')
@mock.patch('openedx.features.course_experience.utils.discount_percentage')
@mock.patch('openedx.features.course_experience.utils.can_receive_discount')
@ddt.data(
[True, 15],
[True, 13],

View File

@@ -213,3 +213,30 @@ def get_resume_block(block):
if resume_block:
return resume_block
return block
def get_first_purchase_offer_banner_fragment(user, course):
if user and course:
discount_expiration_date = get_discount_expiration_date(user, course)
if (discount_expiration_date and
can_receive_discount(user=user, course=course, discount_expiration_date=discount_expiration_date)):
# Translator: xgettext:no-python-format
offer_message = _(u'{banner_open} Upgrade by {discount_expiration_date} and save {percentage}% '
u'[{strikeout_price}]{span_close}{br}Discount will be automatically applied at checkout. '
u'{a_open}Upgrade Now{a_close}{div_close}')
return Fragment(HTML(offer_message).format(
a_open=HTML(u'<a href="{upgrade_link}">').format(
upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
),
a_close=HTML('</a>'),
br=HTML('<br>'),
banner_open=HTML(
'<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">'
),
discount_expiration_date=discount_expiration_date.strftime(u'%B %d'),
percentage=discount_percentage(),
span_close=HTML('</span>'),
div_close=HTML('</div>'),
strikeout_price=HTML(format_strikeout_price(user, course, check_for_discount=False)[0])
))
return None

View File

@@ -30,7 +30,7 @@ from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from openedx.core.djangoapps.util.maintenance_banner import add_maintenance_banner
from openedx.features.course_duration_limits.access import generate_course_expired_fragment
from openedx.features.course_experience.course_tools import CourseToolsPluginManager
from openedx.features.discounts.utils import get_first_purchase_offer_banner_fragment
from openedx.features.course_experience.utils import get_first_purchase_offer_banner_fragment
from openedx.features.discounts.utils import format_strikeout_price
from student.models import CourseEnrollment
from util.views import ensure_valid_course_key

View File

@@ -49,10 +49,6 @@ def get_discount_expiration_date(user, course):
Returns the date when the discount expires for the user.
Returns none if the user is not enrolled.
"""
# anonymous users should never get the discount
if user.is_anonymous:
return None
course_enrollment = CourseEnrollment.objects.filter(
user=user,
course=course.id,
@@ -103,6 +99,10 @@ def can_receive_discount(user, course, discount_expiration_date=None):
# TODO: Add additional conditions to return False here
# anonymous users should never get the discount
if user.is_anonymous:
return False
# Check if discount has expired
if not discount_expiration_date:
discount_expiration_date = get_discount_expiration_date(user, course)

View File

@@ -4,14 +4,9 @@ Utility functions for working with discounts and discounted pricing.
from django.utils.translation import ugettext as _
from course_modes.models import get_course_prices, format_course_price
from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link
from openedx.core.djangolib.markup import HTML
from web_fragments.fragment import Fragment
from openedx.features.discounts.applicability import (
can_receive_discount,
get_discount_expiration_date,
discount_percentage
)
from .applicability import can_receive_discount, discount_percentage
def format_strikeout_price(user, course, base_price=None, check_for_discount=True):
@@ -60,35 +55,3 @@ def format_strikeout_price(user, course, base_price=None, check_for_discount=Tru
)
else:
return (HTML(u"<span class='price'>{}</span>").format(original_price), False)
def get_first_purchase_offer_banner_fragment(user, course):
"""
Return an HTML Fragment with First Purcahse Discount message,
which has the discount_expiration_date, price,
discount percentage and a link to upgrade.
"""
if user and course:
discount_expiration_date = get_discount_expiration_date(user, course)
if (discount_expiration_date and
can_receive_discount(user=user, course=course, discount_expiration_date=discount_expiration_date)):
# Translator: xgettext:no-python-format
offer_message = _(u'{banner_open} Upgrade by {discount_expiration_date} and save {percentage}% '
u'[{strikeout_price}]{span_close}{br}Discount will be automatically applied at checkout. '
u'{a_open}Upgrade Now{a_close}{div_close}')
return Fragment(HTML(offer_message).format(
a_open=HTML(u'<a href="{upgrade_link}">').format(
upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
),
a_close=HTML('</a>'),
br=HTML('<br>'),
banner_open=HTML(
'<div class="first-purchase-offer-banner"><span class="first-purchase-offer-banner-bold">'
),
discount_expiration_date=discount_expiration_date.strftime(u'%B %d'),
percentage=discount_percentage(),
span_close=HTML('</span>'),
div_close=HTML('</div>'),
strikeout_price=HTML(format_strikeout_price(user, course, check_for_discount=False)[0])
))
return None