From 4fba472139551fa95eb1dbf127ddc089e8955ef6 Mon Sep 17 00:00:00 2001 From: Bill DeRusha Date: Fri, 16 Feb 2018 14:39:59 -0500 Subject: [PATCH] Discssions as a plugin --- cms/envs/common.py | 3 --- lms/djangoapps/discussion/__init__.py | 11 ----------- lms/djangoapps/discussion/apps.py | 18 ++++++++++++++++++ lms/djangoapps/discussion/config/__init__.py | 11 +++++++++++ lms/djangoapps/discussion/plugins.py | 2 +- lms/djangoapps/discussion/settings/__init__.py | 0 lms/djangoapps/discussion/settings/common.py | 6 ++++++ lms/djangoapps/discussion/views.py | 2 +- lms/envs/common.py | 11 +---------- lms/urls.py | 6 ------ openedx/core/constants.py | 12 ++++++++++++ setup.py | 1 + 12 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 lms/djangoapps/discussion/settings/__init__.py create mode 100644 lms/djangoapps/discussion/settings/common.py create mode 100644 openedx/core/constants.py diff --git a/cms/envs/common.py b/cms/envs/common.py index 85307f775d..7547afdb05 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -262,9 +262,6 @@ FEATURES = { # Enable credit eligibility feature 'ENABLE_CREDIT_ELIGIBILITY': ENABLE_CREDIT_ELIGIBILITY, - # Can the visibility of the discussion tab be configured on a per-course basis? - 'ALLOW_HIDING_DISCUSSION_TAB': False, - # Special Exams, aka Timed and Proctored Exams 'ENABLE_SPECIAL_EXAMS': False, diff --git a/lms/djangoapps/discussion/__init__.py b/lms/djangoapps/discussion/__init__.py index 2ab03ad9fc..e69de29bb2 100644 --- a/lms/djangoapps/discussion/__init__.py +++ b/lms/djangoapps/discussion/__init__.py @@ -1,11 +0,0 @@ -""" -Discussion settings and flags. -""" - -from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace - -# Namespace for course experience waffle flags. -WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='edx_discussions') - -# Waffle flag to enable the use of Bootstrap -USE_BOOTSTRAP_FLAG = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'use_bootstrap') diff --git a/lms/djangoapps/discussion/apps.py b/lms/djangoapps/discussion/apps.py index 75daaf62cf..5e98707ef6 100644 --- a/lms/djangoapps/discussion/apps.py +++ b/lms/djangoapps/discussion/apps.py @@ -6,12 +6,30 @@ Signal handlers are connected here. from django.apps import AppConfig +from openedx.core.constants import COURSE_ID_PATTERN +from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType, PluginURLs, PluginSettings + class DiscussionConfig(AppConfig): """ Application Configuration for Grades. """ + name = u'lms.djangoapps.discussion' + plugin_app = { + PluginURLs.CONFIG: { + ProjectType.LMS: { + PluginURLs.NAMESPACE: u'', + PluginURLs.REGEX: r'^courses/{}/discussion/forum/'.format(COURSE_ID_PATTERN), + PluginURLs.RELATIVE_PATH: u'urls', + } + }, + PluginSettings.CONFIG: { + ProjectType.LMS: { + SettingsType.COMMON: {PluginSettings.RELATIVE_PATH: u'settings.common'}, + } + } + } def ready(self): """ diff --git a/lms/djangoapps/discussion/config/__init__.py b/lms/djangoapps/discussion/config/__init__.py index e69de29bb2..2ab03ad9fc 100644 --- a/lms/djangoapps/discussion/config/__init__.py +++ b/lms/djangoapps/discussion/config/__init__.py @@ -0,0 +1,11 @@ +""" +Discussion settings and flags. +""" + +from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace + +# Namespace for course experience waffle flags. +WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='edx_discussions') + +# Waffle flag to enable the use of Bootstrap +USE_BOOTSTRAP_FLAG = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'use_bootstrap') diff --git a/lms/djangoapps/discussion/plugins.py b/lms/djangoapps/discussion/plugins.py index 80ad03e670..822b2c4431 100644 --- a/lms/djangoapps/discussion/plugins.py +++ b/lms/djangoapps/discussion/plugins.py @@ -9,7 +9,7 @@ import django_comment_client.utils as utils from courseware.tabs import EnrolledTab from xmodule.tabs import TabFragmentViewMixin -from . import USE_BOOTSTRAP_FLAG +from .config import USE_BOOTSTRAP_FLAG class DiscussionTab(TabFragmentViewMixin, EnrolledTab): diff --git a/lms/djangoapps/discussion/settings/__init__.py b/lms/djangoapps/discussion/settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lms/djangoapps/discussion/settings/common.py b/lms/djangoapps/discussion/settings/common.py new file mode 100644 index 0000000000..313c569b2d --- /dev/null +++ b/lms/djangoapps/discussion/settings/common.py @@ -0,0 +1,6 @@ +"""Common environment variables unique to the discussion plugin.""" + + +def plugin_settings(settings): + """Settings for the discussions plugin. """ + settings.FEATURES['ALLOW_HIDING_DISCUSSION_TAB'] = False diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index ea65910d6a..cce8360d4f 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -49,7 +49,7 @@ from student.models import CourseEnrollment from util.json_request import JsonResponse, expect_json from xmodule.modulestore.django import modulestore -from . import USE_BOOTSTRAP_FLAG +from .config import USE_BOOTSTRAP_FLAG log = logging.getLogger("edx.discussions") diff --git a/lms/envs/common.py b/lms/envs/common.py index bfc3191af7..ebf86068c6 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -37,6 +37,7 @@ import django from path import Path as path from django.utils.translation import ugettext_lazy as _ +from openedx.core.constants import COURSE_KEY_REGEX, COURSE_KEY_PATTERN, COURSE_ID_PATTERN from openedx.core.djangoapps.theming.helpers_dirs import ( get_themes_unchecked, get_theme_base_dirs_from_settings @@ -709,15 +710,6 @@ COURSE_MODE_DEFAULTS = { # TODO (vshnayder): Will probably need to change as we get real access control in. LMS_MIGRATION_ALLOWED_IPS = [] -# These are standard regexes for pulling out info like course_ids, usage_ids, etc. -# They are used so that URLs with deprecated-format strings still work. -# Note: these intentionally greedily grab all chars up to the next slash including any pluses -# DHM: I really wanted to ensure the separators were the same (+ or /) but all patts I tried had -# too many inadvertent side effects :-( -COURSE_KEY_PATTERN = r'(?P[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)' -COURSE_ID_PATTERN = COURSE_KEY_PATTERN.replace('course_key_string', 'course_id') -COURSE_KEY_REGEX = COURSE_KEY_PATTERN.replace('P', ':') - USAGE_KEY_PATTERN = r'(?P(?:i4x://?[^/]+/[^/]+/[^/]+/[^@]+(?:@[^/]+)?)|(?:[^/]+))' ASSET_KEY_PATTERN = r'(?P(?:/?c4x(:/)?/[^/]+/[^/]+/[^/]+/[^@]+(?:@[^/]+)?)|(?:[^/]+))' USAGE_ID_PATTERN = r'(?P(?:i4x://?[^/]+/[^/]+/[^/]+/[^@]+(?:@[^/]+)?)|(?:[^/]+))' @@ -2189,7 +2181,6 @@ INSTALLED_APPS = [ 'django_comment_client', 'django_comment_common', 'discussion_api', - 'lms.djangoapps.discussion.apps.DiscussionConfig', # Notes 'notes', diff --git a/lms/urls.py b/lms/urls.py index 4f4dd66ffc..0a262dbd4f 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -734,12 +734,6 @@ if settings.FEATURES.get('ENABLE_DISCUSSION_SERVICE'): ), include('django_comment_client.urls') ), - url( - r'^courses/{}/discussion/forum/'.format( - settings.COURSE_ID_PATTERN, - ), - include('discussion.urls') - ), url( r'^notification_prefs/enable/', notification_prefs_views.ajax_enable diff --git a/openedx/core/constants.py b/openedx/core/constants.py new file mode 100644 index 0000000000..d1e8f79ae8 --- /dev/null +++ b/openedx/core/constants.py @@ -0,0 +1,12 @@ +""" +Constants that are relevant all of Open edX +""" +# These are standard regexes for pulling out info like course_ids, usage_ids, etc. +# They are used so that URLs with deprecated-format strings still work. +# Note: these intentionally greedily grab all chars up to the next slash includingny pluses +# DHM: I really wanted to ensure the separators were the same (+ or /) but all patts tried had +# too many inadvertent side effects :-( + +COURSE_KEY_PATTERN = r'(?P[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)' +COURSE_ID_PATTERN = COURSE_KEY_PATTERN.replace('course_key_string', 'course_id') +COURSE_KEY_REGEX = COURSE_KEY_PATTERN.replace('P', ':') diff --git a/setup.py b/setup.py index 0e9845e2e0..3485a97405 100644 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ setup( ], "lms.djangoapp": [ "ace_common = openedx.core.djangoapps.ace_common.apps:AceCommonConfig", + "discussion = lms.djangoapps.discussion.apps:DiscussionConfig", "grades = lms.djangoapps.grades.apps:GradesConfig", "plugins = openedx.core.djangoapps.plugins.apps:PluginsConfig", "schedules = openedx.core.djangoapps.schedules.apps:SchedulesConfig",