Skip to content

Commit

Permalink
Merge pull request openedx#1122 from proversity-org/ir/pearson/PE-785
Browse files Browse the repository at this point in the history
PE-785 - Adding custom course home feature
  • Loading branch information
Diego Millan authored Nov 21, 2019
2 parents a72cee6 + 6be5eb9 commit 9c8a7d2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
)
from openedx.core.djangoapps.models.course_details import CourseDetails
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from openedx.core.djangoapps.plugins.plugin_extension_points import run_extension_point
from openedx.core.djangoapps.programs.utils import ProgramMarketingDataExtender
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
Expand Down Expand Up @@ -312,6 +313,15 @@ def course_info(request, course_id):
Assumes the course_id is in a valid format.
"""
custom_course_home = run_extension_point(
'OEE_COURSE_HOME_CALCULATOR',
course_id=course_id,
user=request.user,
)

if custom_course_home:
return redirect(custom_course_home)

# TODO: LEARNER-611: This can be deleted with Course Info removal. The new
# Course Home is using its own processing of last accessed.
def get_last_accessed_courseware(course, request, user):
Expand Down
46 changes: 46 additions & 0 deletions openedx/core/djangoapps/plugins/plugin_extension_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Plugin extension points module
"""
import logging
from importlib import import_module

from django.conf import settings

from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers

log = logging.getLogger(__name__)


def run_extension_point(extension_point, *args, **kwargs):
"""
Wrapper function to execute any extension point at platform level
if exceptions occurs returns None.
"""
path = None

try:
path = configuration_helpers.get_value(
extension_point,
getattr(settings, extension_point, None),
)

if not path:
return None
except AttributeError:
return None

try:
module_name, func_name = path.rsplit('.', 1)
module = import_module(module_name)
extension_function = getattr(module, func_name)

return extension_function(*args, **kwargs)
except ImportError:
log.info('Could not import the %s : %s', extension_point, module)
return None
except AttributeError:
log.info('Could not import the function %s in the module %s', func_name, module)
return None
except ValueError:
log.info('Could not load the information from \"%s\"', path)
return None
11 changes: 11 additions & 0 deletions openedx/features/course_experience/views/course_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from django.urls import reverse
from django.shortcuts import redirect
from django.template.context_processors import csrf
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
Expand All @@ -24,6 +25,7 @@
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.courseware.views.views import CourseTabView
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from openedx.core.djangoapps.plugins.plugin_extension_points import run_extension_point
from openedx.core.djangoapps.util.maintenance_banner import add_maintenance_banner
from openedx.features.course_experience.course_tools import CourseToolsPluginManager
from openedx.features.course_duration_limits.access import generate_course_expired_fragment
Expand Down Expand Up @@ -58,6 +60,15 @@ def get(self, request, course_id, **kwargs):
"""
Displays the home page for the specified course.
"""
custom_course_home = run_extension_point(
'OEE_COURSE_HOME_CALCULATOR',
course_id=course_id,
user=request.user,
)

if custom_course_home:
return redirect(custom_course_home)

return super(CourseHomeView, self).get(request, course_id, 'courseware', **kwargs)

def uses_bootstrap(self, request, course, tab):
Expand Down

0 comments on commit 9c8a7d2

Please sign in to comment.