Add cosmetic price field to studio & logic
- Price field added to Advanced Settings - Function that decides which price to display - Test added to check that the function outputs correct price - Added feature flag and conditional to decide whether to display course price or not - Feature Flag to show or hide course price on Course About page sidebar when not using shopping cart
This commit is contained in:
@@ -199,6 +199,24 @@ class ViewsTestCase(TestCase):
|
||||
mock_course.id = self.course_key
|
||||
self.assertTrue(views.registered_for_course(mock_course, self.user))
|
||||
|
||||
@override_settings(PAID_COURSE_REGISTRATION_CURRENCY=["USD", "$"])
|
||||
def test_get_cosmetic_display_price(self):
|
||||
"""
|
||||
Check that get_cosmetic_display_price() returns the correct price given its inputs.
|
||||
"""
|
||||
registration_price = 99
|
||||
self.course.cosmetic_display_price = 10
|
||||
# Since registration_price is set, it overrides the cosmetic_display_price and should be returned
|
||||
self.assertEqual(views.get_cosmetic_display_price(self.course, registration_price), "$99")
|
||||
|
||||
registration_price = 0
|
||||
# Since registration_price is not set, cosmetic_display_price should be returned
|
||||
self.assertEqual(views.get_cosmetic_display_price(self.course, registration_price), "$10")
|
||||
|
||||
self.course.cosmetic_display_price = 0
|
||||
# Since both prices are not set, there is no price, thus "Free"
|
||||
self.assertEqual(views.get_cosmetic_display_price(self.course, registration_price), "Free")
|
||||
|
||||
def test_jump_to_invalid(self):
|
||||
# TODO add a test for invalid location
|
||||
# TODO add a test for no data *
|
||||
|
||||
@@ -739,6 +739,25 @@ def registered_for_course(course, user):
|
||||
return False
|
||||
|
||||
|
||||
def get_cosmetic_display_price(course, registration_price):
|
||||
"""
|
||||
Return Course Price as a string preceded by correct currency, or 'Free'
|
||||
"""
|
||||
currency_symbol = settings.PAID_COURSE_REGISTRATION_CURRENCY[1]
|
||||
|
||||
price = course.cosmetic_display_price
|
||||
if registration_price > 0:
|
||||
price = registration_price
|
||||
|
||||
if price:
|
||||
# Translators: This will look like '$50', where {currency_symbol} is a symbol such as '$' and {price} is a
|
||||
# numerical amount in that currency. Adjust this display as needed for your language.
|
||||
return _("{currency_symbol}{price}").format(currency_symbol=currency_symbol, price=price)
|
||||
else:
|
||||
# Translators: This refers to the cost of the course. In this case, the course costs nothing so it is free.
|
||||
return _('Free')
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@cache_if_anonymous()
|
||||
def course_about(request, course_id):
|
||||
@@ -795,6 +814,8 @@ def course_about(request, course_id):
|
||||
reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
|
||||
reg_url=reverse('register_user'), course_id=course.id.to_deprecated_string())
|
||||
|
||||
course_price = get_cosmetic_display_price(course, registration_price)
|
||||
|
||||
# Used to provide context to message to student if enrollment not allowed
|
||||
can_enroll = has_access(request.user, 'enroll', course)
|
||||
invitation_only = course.invitation_only
|
||||
@@ -817,8 +838,8 @@ def course_about(request, course_id):
|
||||
'studio_url': studio_url,
|
||||
'registered': registered,
|
||||
'course_target': course_target,
|
||||
'registration_price': registration_price,
|
||||
'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1],
|
||||
'is_cosmetic_price_enabled': settings.FEATURES.get('ENABLE_COSMETIC_DISPLAY_PRICE'),
|
||||
'course_price': course_price,
|
||||
'in_cart': in_cart,
|
||||
'reg_then_add_to_cart_link': reg_then_add_to_cart_link,
|
||||
'show_courseware_link': show_courseware_link,
|
||||
|
||||
Reference in New Issue
Block a user