Good point, but keep in mind I asked the question 2 years ago. For an newer
question of mine, please see
https://discuss.openedx.org/t/migrate-from-eucalyptus-to-juniper/2881

=]

Samuel Marks
Charity <https://sydneyscientific.org> | consultancy <https://offscale.io>
| open-source <https://github.com/offscale> | LinkedIn
<https://linkedin.com/in/samuelmarks>


On Mon, Jul 27, 2020 at 10:22 PM Isanka Wijerathne <isank...@gmail.com>
wrote:

> You can add a default value to return
>
> For Python 2 versions
>
> return min(mode.min_price for mode in modes if mode.currency.lower() ==
> currency.lower() or [0])
>
> For Python 3 versions
>
> return min(mode.min_price for mode in modes if mode.currency.lower() ==
> currency.lower(),  default=0)
>
>
>
> On Wednesday, February 21, 2018 at 7:35:07 AM UTC+9, Samuel Marks wrote:
>>
>> Actual fix, I ended up just copying
>> min_course_price_for_verified_for_currency:
>>
>>     @classmethod
>>     def min_course_price_for_currency(cls, course_id, currency):
>>         """
>>         Returns the minimum price of the course in the appropriate
>> currency over all the course's
>>         non-expired modes.
>>         If there is no mode found, will return the price of DEFAULT_MODE,
>> which is 0
>>         """
>>         modes = cls.modes_for_course(course_id)
>>         for mode in modes:
>>             if mode.currency.lower() == currency.lower() and mode.
>> min_price:
>>                 return mode.min_price
>>         return 0
>>
>> On Wednesday, February 21, 2018 at 9:21:14 AM UTC+11, Samuel Marks wrote:
>>>
>>> Is this a bug I should report, or have I misconfigured?
>>>
>>> Feb 20 22:12:35 OpenEdX4 [service_variant=lms][django.request][env:
>>> sandbox] ERROR [OpenEdX4  3812] [base.py:256] - Internal Server Error:
>>> /courses/course-v1:mycourseid/about
>>> Traceback (most recent call last):
>>>   File
>>> "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py"
>>> , line 132, in get_response
>>>     response = wrapped_callback(request, *callback_args, **
>>> callback_kwargs)
>>>   File
>>> "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py"
>>> , line 145, in inner
>>>     return func(*args, **kwargs)
>>>   File
>>> "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py"
>>> , line 110, in _wrapped_view
>>>     response = view_func(request, *args, **kwargs)
>>>   File "/edx/app/edxapp/edx-platform/common/djangoapps/util/views.py",
>>> line 49, in inner
>>>     response = view_func(request, *args, **kwargs)
>>>   File "/edx/app/edxapp/edx-platform/common/djangoapps/util/cache.py",
>>> line 83, in wrapper
>>>     return view_func(request, *args, **kwargs)
>>>   File
>>> "/edx/app/edxapp/edx-platform/lms/djangoapps/courseware/views/views.py",
>>> line 762, in course_about
>>>     registration_price, course_price = get_course_prices(course)
>>>   File
>>> "/edx/app/edxapp/edx-platform/lms/djangoapps/courseware/views/views.py",
>>> line 607, in get_course_prices
>>>     settings.PAID_COURSE_REGISTRATION_CURRENCY[0]
>>>   File
>>> "/edx/app/edxapp/edx-platform/common/djangoapps/course_modes/models.py",
>>> line 649, in min_course_price_for_currency
>>>     return min(mode.min_price for mode in modes if mode.currency.lower()
>>> == currency.lower())
>>> ValueError: min() arg is an empty sequence
>>>
>>> In the meantime, I've rewritten mine to:
>>>
>>> @classmethod
>>>     def min_course_price_for_currency(cls, course_id, currency):
>>>         """
>>>         Returns the minimum price of the course in the appropriate
>>> currency over all the course's
>>>         non-expired modes.
>>>         If there is no mode found, will return the price of
>>> DEFAULT_MODE, which is 0
>>>         """
>>>         modes = cls.modes_for_course(course_id)
>>>         if modes:
>>>             return min(mode.min_price for mode in modes if mode.currency
>>> .lower() == currency.lower())
>>>         return cls.DEFAULT_MODE
>>>
>>> (was:
>>> https://github.com/edx/edx-platform/blob/25130ae3c8333e5353ab88860c76619ebb9098f9/common/djangoapps/course_modes/models.py#L674
>>> )
>>>
>> --
> ***Please note! This Google Group has been deprecated - visit
> https://discuss.openedx.org/
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "General Open edX discussion" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/edx-code/sB_ZPfqee2U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> edx-code+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/edx-code/121602ba-6bb1-4b7a-ad8a-0edbbdd7e9dfo%40googlegroups.com
> <https://groups.google.com/d/msgid/edx-code/121602ba-6bb1-4b7a-ad8a-0edbbdd7e9dfo%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
***Please note! This Google Group has been deprecated - visit 
https://discuss.openedx.org/
--- 
You received this message because you are subscribed to the Google Groups 
"General Open edX discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to edx-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/edx-code/CAMfPbcZM7GrDfRkP_%2BGhwVTn5KZTduCMqEQW4OFZB7r9i4iqfw%40mail.gmail.com.

Reply via email to