Files
edx-platform/lms/djangoapps/learner_dashboard/utils.py
2023-06-21 15:56:35 +05:00

69 lines
1.8 KiB
Python

"""
The utility methods and functions to help the djangoapp logic
"""
from django.core.exceptions import ObjectDoesNotExist
from opaque_keys.edx.keys import CourseKey
from common.djangoapps.student.roles import GlobalStaff
from lms.djangoapps.learner_dashboard.config.waffle import (
ENABLE_B2C_SUBSCRIPTIONS,
ENABLE_MASTERS_PROGRAM_TAB_VIEW,
ENABLE_PROGRAM_TAB_VIEW
)
from lms.djangoapps.program_enrollments.api import get_program_enrollment
FAKE_COURSE_KEY = CourseKey.from_string('course-v1:fake+course+run')
def strip_course_id(path):
"""
The utility function to help remove the fake
course ID from the url path
"""
course_id = str(FAKE_COURSE_KEY)
return path.split(course_id)[0]
def program_tab_view_is_enabled() -> bool:
"""
check if program discussion is enabled.
"""
return ENABLE_PROGRAM_TAB_VIEW.is_enabled()
def masters_program_tab_view_is_enabled() -> bool:
"""
check if masters program discussion is enabled.
"""
return ENABLE_MASTERS_PROGRAM_TAB_VIEW.is_enabled()
def is_enrolled_or_staff(request, program_uuid):
"""Returns true if the user is enrolled in the program or staff"""
if GlobalStaff().has_user(request.user):
return True
try:
get_program_enrollment(program_uuid=program_uuid, user=request.user)
except ObjectDoesNotExist:
return False
return True
def b2c_subscriptions_is_enabled() -> bool:
"""
Check if B2C program subscriptions flag is enabled.
"""
return ENABLE_B2C_SUBSCRIPTIONS.is_enabled()
def b2c_subscriptions_enabled(is_mobile=False) -> bool:
"""
Check whether B2C Subscriptions pages should be shown to user.
"""
if not is_mobile and b2c_subscriptions_is_enabled():
return True
return False