diff --git a/ecommerce/core/context_processors.py b/ecommerce/core/context_processors.py index 6c62ba12ba4..818a4298b09 100644 --- a/ecommerce/core/context_processors.py +++ b/ecommerce/core/context_processors.py @@ -1,5 +1,8 @@ +from babel.numbers import get_currency_symbol +from django.conf import settings + from ecommerce.core.url_utils import get_favicon_url, get_lms_dashboard_url, get_lms_url, get_logo_url @@ -16,3 +19,20 @@ def core(request): 'favicon_url': get_favicon_url(), 'optimizely_snippet_src': site_configuration.optimizely_snippet_src, } + + +def localization(_request): + defaults = getattr(settings, "COURSE_MODE_DEFAULTS", {}) + default_currency = defaults.get("currency") + registration_currency = getattr(settings, "PAID_COURSE_REGISTRATION_CURRENCY", None) + currency_code = registration_currency or default_currency or "USD" + + if not isinstance(currency_code, str): + raise ValueError(f"Currency code must be a string; currently: {currency_code}") + + return { + # Note: babel returns code if not found + # get_currency_symbol("XYZ") => "XYZ" + "currency_symbol_": get_currency_symbol(currency_code), + "currency_code_": currency_code, + } diff --git a/ecommerce/courses/tests/test_views.py b/ecommerce/courses/tests/test_views.py index 313ec1ef556..ea875fb612c 100644 --- a/ecommerce/courses/tests/test_views.py +++ b/ecommerce/courses/tests/test_views.py @@ -133,6 +133,25 @@ def test_credit_providers_in_context(self): json.loads(provider_json), ) + @responses.activate + def test_currency_localization(self): + """Verify the currency symbol is localized based on settings""" + self._create_and_login_staff_user() + self.mock_access_token_response() + __ = self.mock_credit_api_providers() + + response = self.client.get(self.path) + self.assertEqual(response.status_code, 200) + # default is USD + self.assertEqual(response.context["currency_symbol_"], "$") + self.assertEqual(response.context["currency_code_"], "USD") + + with self.settings(PAID_COURSE_REGISTRATION_CURRENCY="GBP"): + response = self.client.get(self.path) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context["currency_symbol_"], "£") + self.assertEqual(response.context["currency_code_"], "GBP") + @responses.activate def test_credit_providers_in_context_cached(self): """ Verify the cached context data includes a list of credit providers. """ diff --git a/ecommerce/settings/base.py b/ecommerce/settings/base.py index 6432d0969a8..76e8e4689ae 100644 --- a/ecommerce/settings/base.py +++ b/ecommerce/settings/base.py @@ -208,6 +208,7 @@ 'oscar.apps.communication.notifications.context_processors.notifications', 'oscar.core.context_processors.metadata', 'ecommerce.core.context_processors.core', + "ecommerce.core.context_processors.localization", 'ecommerce.extensions.analytics.context_processors.analytics', ), 'debug': True, # Django will only display debug pages if the global DEBUG setting is set to True. diff --git a/ecommerce/static/templates/_course_credit_seats.html b/ecommerce/static/templates/_course_credit_seats.html index b8d147b2319..804ea19acaa 100644 --- a/ecommerce/static/templates/_course_credit_seats.html +++ b/ecommerce/static/templates/_course_credit_seats.html @@ -21,7 +21,7 @@ <% _.each(creditSeats, function (seat) { %> <%= seat.get('credit_provider_display_name') %> - <%= '$' + Number(seat.get('price')).toLocaleString() %> + <%= currencySymbol + Number(seat.get('price')).toLocaleString() %> <%= seat.get('credit_hours') %> <% var expires = seat.get('expires'); if (expires) { diff --git a/ecommerce/static/templates/_course_seat.html b/ecommerce/static/templates/_course_seat.html index 4391e3107c5..e91fb0bf8fb 100644 --- a/ecommerce/static/templates/_course_seat.html +++ b/ecommerce/static/templates/_course_seat.html @@ -3,7 +3,7 @@
<%= seat.getSeatTypeDisplayName() %>
-
<%= gettext('Price:') + ' $' + Number(seat.get('price')).toLocaleString() %>
+
<%= gettext('Price:') + ' ' + currencySymbol + Number(seat.get('price')).toLocaleString() %>
<% var expires = seat.get('expires'); if(expires) { print(gettext('Upgrade Deadline:') + ' ' + moment.utc(expires).format('lll z')); diff --git a/ecommerce/static/templates/_offer_course_list.html b/ecommerce/static/templates/_offer_course_list.html index 8eb7ffc9142..e02779aba3e 100644 --- a/ecommerce/static/templates/_offer_course_list.html +++ b/ecommerce/static/templates/_offer_course_list.html @@ -52,12 +52,12 @@
- <%= gettext('Price (in USD)') %>: $0.00 + <%= gettext('Price (in USD)') %>: {{ currency_symbol_ }}0.00 diff --git a/ecommerce/static/templates/coupon_form.html b/ecommerce/static/templates/coupon_form.html index 8255d9567fe..eff1568a97c 100644 --- a/ecommerce/static/templates/coupon_form.html +++ b/ecommerce/static/templates/coupon_form.html @@ -1,249 +1,510 @@
-
-
- - -

+
+
+ + +

+
+
+ + +

+
+
+ + +

+
+ +
+
+ +
+
+ +
+
-
- - -

+

+
+
+ +
+
+ +
+
-
- -

+
-
-
- -
-
- -
-

-
-
- -
-
- -
-

-
-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ + +

+
-
- - -

-
+
+ +
+
+ +
+
+ + + + +
+

+
-
- -
-
- -
-
- - - - -
-

-
+
+ + +

+
+
-
- - -

+
+ +
+
+ +
-
- -
- -
-
- - -
-
- - -
-
- - -
-
+
+ +
- -
- - -

+
+ +
+
+
-
- -
-
$
- -
-

-
+
+ + +

+
-
- -
-
- -
-

-
+
+ +
+
$
+ +
+

+
-