From 128d4836c042aa8131b9cdda2a56f3b003f0596a Mon Sep 17 00:00:00 2001 From: stephensanchez Date: Wed, 22 Oct 2014 20:26:03 +0000 Subject: [PATCH] Change design to check for min price or suggested prices. --- common/djangoapps/course_modes/models.py | 19 +++++++++++++++++++ .../course_modes/tests/test_models.py | 19 +++++++++++++++++++ common/djangoapps/student/views.py | 4 ++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index 072f8e79a0..94466bf20d 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -163,6 +163,25 @@ class CourseMode(models.Model): return mode.min_price return 0 + @classmethod + def has_payment_options(cls, course_id): + """Determines if there is any mode that has payment options + + Check the dict of course modes and see if any of them have a minimum price or + suggested prices. Returns True if any course mode has a payment option. + + Args: + course_mode_dict (dict): Dictionary mapping course mode slugs to Modes + + Returns: + True if any course mode has a payment option. + + """ + for mode in cls.modes_for_course(course_id): + if mode.min_price > 0 or mode.suggested_prices != '': + return True + return False + @classmethod def min_course_price_for_currency(cls, course_id, currency): """ diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index c369aaaf0f..88571d449d 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -127,3 +127,22 @@ class CourseModeModelTest(TestCase): mode = CourseMode.verified_mode_for_course(self.course_key) self.assertEqual(mode.slug, 'professional') + + def test_course_has_payment_options(self): + # Has no payment options. + honor, _ = self.create_mode('honor', 'Honor') + self.assertFalse(CourseMode.has_payment_options(self.course_key)) + + # Now we do have a payment option. + verified, _ = self.create_mode('verified', 'Verified', min_price=5) + self.assertTrue(CourseMode.has_payment_options(self.course_key)) + + # Unset verified's minimum price. + verified.min_price = 0 + verified.save() + self.assertFalse(CourseMode.has_payment_options(self.course_key)) + + # Finally, give the honor mode payment options + honor.suggested_prices = '5, 10, 15' + honor.save() + self.assertTrue(CourseMode.has_payment_options(self.course_key)) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 4c941818fa..eb23c1f876 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -699,8 +699,8 @@ def _allow_donation(course_modes, course_id): """ donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) - is_microsite = microsite.is_request_in_microsite() - return donations_enabled and not is_verified_mode and not is_microsite + has_payment_option = CourseMode.has_payment_options(course_id) + return donations_enabled and not is_verified_mode and not has_payment_option def try_change_enrollment(request):