From 2f1936ce735d2db5400e3d34330e80d50ac6157e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 13 Apr 2017 17:11:43 -0400 Subject: [PATCH] Replace context processor with new help-tokens app This makes it possible to refer to multiple book from a single app. This also means that Open edX branches will be able to pass bok-choy tests (at least if the books have already been built.) --- .../contentstore/context_processors.py | 28 ----- cms/envs/aws.py | 2 +- cms/envs/bok_choy.py | 7 ++ cms/envs/common.py | 7 +- cms/startup.py | 5 + cms/templates/widgets/header.html | 1 - cms/urls.py | 3 + .../djangoapps/util/help_context_processor.py | 116 ------------------ .../util/tests/test_help_context_processor.py | 57 --------- common/test/acceptance/tests/helpers.py | 29 ++++- .../acceptance/tests/lms/test_lms_help.py | 35 ++---- .../tests/studio/test_studio_help.py | 73 ++--------- docs/cms_config.ini | 72 +++++------ docs/lms_config.ini | 54 +++----- lms/djangoapps/context_processors.py | 28 ----- lms/envs/aws.py | 2 +- lms/envs/bok_choy.py | 9 +- lms/envs/common.py | 8 +- lms/startup.py | 8 +- .../cohort-group-header.underscore | 4 +- lms/templates/navigation.html | 1 - lms/urls.py | 3 + requirements/edx/github.txt | 1 + 23 files changed, 148 insertions(+), 405 deletions(-) delete mode 100644 cms/djangoapps/contentstore/context_processors.py delete mode 100644 common/djangoapps/util/help_context_processor.py delete mode 100644 common/djangoapps/util/tests/test_help_context_processor.py delete mode 100644 lms/djangoapps/context_processors.py diff --git a/cms/djangoapps/contentstore/context_processors.py b/cms/djangoapps/contentstore/context_processors.py deleted file mode 100644 index 082e52c654..0000000000 --- a/cms/djangoapps/contentstore/context_processors.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -Django Template Context Processor for CMS Online Contextual Help -""" -import ConfigParser -from django.conf import settings - -from util.help_context_processor import common_doc_url - - -# Open and parse the configuration file when the module is initialized -CONFIG_FILE = open(settings.REPO_ROOT / "docs" / "cms_config.ini") -CONFIG = ConfigParser.ConfigParser() -CONFIG.readfp(CONFIG_FILE) - - -def doc_url(request=None): # pylint: disable=unused-argument - """ - This function is added in the list of TEMPLATES 'context_processors' OPTION, which is a django setting for - a tuple of callables that take a request object as their argument and return a dictionary of items - to be merged into the RequestContext. - - This function returns a dict with get_online_help_info, making it directly available to all mako templates. - - Args: - request: Currently not used, but is passed by django to context processors. - May be used in the future for determining the language of choice. - """ - return common_doc_url(request, CONFIG) diff --git a/cms/envs/aws.py b/cms/envs/aws.py index 9285afe7e5..6de3003276 100644 --- a/cms/envs/aws.py +++ b/cms/envs/aws.py @@ -494,4 +494,4 @@ AFFILIATE_COOKIE_NAME = ENV_TOKENS.get('AFFILIATE_COOKIE_NAME', AFFILIATE_COOKIE ############## Settings for Studio Context Sensitive Help ############## -DOC_LINK_BASE_URL = ENV_TOKENS.get('DOC_LINK_BASE_URL', DOC_LINK_BASE_URL) +HELP_TOKENS_BOOKS = ENV_TOKENS.get('HELP_TOKENS_BOOKS', HELP_TOKENS_BOOKS) diff --git a/cms/envs/bok_choy.py b/cms/envs/bok_choy.py index ae848ac284..48d86f753c 100644 --- a/cms/envs/bok_choy.py +++ b/cms/envs/bok_choy.py @@ -13,6 +13,7 @@ from the same directory. import os from path import Path as path +from openedx.core.release import RELEASE_LINE ########################## Prod-like settings ################################### # These should be as close as possible to the settings we use in production. @@ -127,6 +128,12 @@ MOCK_SEARCH_BACKING_FILE = ( SECRET_KEY = "very_secret_bok_choy_key" LMS_ROOT_URL = "http://localhost:8000" +if RELEASE_LINE == "master": + # On master, acceptance tests use edX books, not the default Open edX books. + HELP_TOKENS_BOOKS = { + 'learner': 'http://edx.readthedocs.io/projects/edx-guide-for-students', + 'course_author': 'http://edx.readthedocs.io/projects/edx-partner-course-staff', + } ##################################################################### # Lastly, see if the developer has any local overrides. diff --git a/cms/envs/common.py b/cms/envs/common.py index eecd597497..da75b610a2 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -89,7 +89,8 @@ from lms.envs.common import ( FILE_UPLOAD_STORAGE_BUCKET_NAME, FILE_UPLOAD_STORAGE_PREFIX, - COURSE_ENROLLMENT_MODES + COURSE_ENROLLMENT_MODES, + HELP_TOKENS_BOOKS, ) from path import Path as path from warnings import simplefilter @@ -300,7 +301,7 @@ TEMPLATES = [ 'django.contrib.auth.context_processors.auth', # this is required for admin 'django.template.context_processors.csrf', 'dealer.contrib.django.staff.context_processor', # access git revision - 'contentstore.context_processors.doc_url', + 'help_tokens.context_processor', ), # Change 'debug' in your environment settings files - not here. 'debug': False @@ -1245,7 +1246,7 @@ AFFILIATE_COOKIE_NAME = 'affiliate_id' ############## Settings for Studio Context Sensitive Help ############## -DOC_LINK_BASE_URL = None +HELP_TOKENS_INI_FILE = REPO_ROOT / "docs" / "cms_config.ini" # Theme directory locale paths COMPREHENSIVE_THEME_LOCALE_PATHS = [] diff --git a/cms/startup.py b/cms/startup.py index c37f315433..47aa0560f9 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -12,6 +12,7 @@ from openedx.core.lib.django_startup import autostartup import django from openedx.core.djangoapps.monkey_patch import django_db_models_options from openedx.core.lib.xblock_utils import xblock_local_resource_url +from openedx.core.release import doc_version import xmodule.x_module import cms.lib.xblock.runtime @@ -45,6 +46,10 @@ def run(): xmodule.x_module.descriptor_global_handler_url = cms.lib.xblock.runtime.handler_url xmodule.x_module.descriptor_global_local_resource_url = xblock_local_resource_url + # Set the version of docs that help-tokens will go to. + settings.HELP_TOKENS_LANGUAGE_CODE = settings.LANGUAGE_CODE + settings.HELP_TOKENS_VERSION = doc_version() + # validate configurations on startup validate_cms_config(settings) diff --git a/cms/templates/widgets/header.html b/cms/templates/widgets/header.html index 763a75461a..595e217934 100644 --- a/cms/templates/widgets/header.html +++ b/cms/templates/widgets/header.html @@ -4,7 +4,6 @@ from django.conf import settings from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ - from contentstore.context_processors import doc_url %>
diff --git a/lms/templates/navigation.html b/lms/templates/navigation.html index bdf8057c45..7f90e06758 100644 --- a/lms/templates/navigation.html +++ b/lms/templates/navigation.html @@ -6,7 +6,6 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ -from context_processors import doc_url from lms.djangoapps.ccx.overrides import get_current_ccx from openedx.core.djangolib.markup import HTML, Text diff --git a/lms/urls.py b/lms/urls.py index babf8f2be3..a9e1d7dcad 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -101,6 +101,9 @@ urlpatterns = ( # URLs for managing dark launches of languages url(r'^update_lang/', include('openedx.core.djangoapps.dark_lang.urls', namespace='dark_lang')), + # For redirecting to help pages. + url(r'^help_token/', include('help_tokens.urls')), + # URLs for API access management url(r'^api-admin/', include('openedx.core.djangoapps.api_admin.urls', namespace='api_admin')), ) diff --git a/requirements/edx/github.txt b/requirements/edx/github.txt index 098f1a1a7c..46bb2619dd 100644 --- a/requirements/edx/github.txt +++ b/requirements/edx/github.txt @@ -89,6 +89,7 @@ git+https://github.com/edx/xblock-utils.git@v1.0.5#egg=xblock-utils==1.0.5 git+https://github.com/edx/edx-user-state-client.git@1.0.1#egg=edx-user-state-client==1.0.1 git+https://github.com/edx/xblock-lti-consumer.git@v1.1.2#egg=lti_consumer-xblock==1.1.2 git+https://github.com/edx/edx-proctoring.git@0.18.0#egg=edx-proctoring==0.18.0 +git+https://github.com/edx/help-tokens.git@nedbat/help-tokens-v1#egg=help-tokens==0.0 # Third Party XBlocks git+https://github.com/open-craft/xblock-poll@v1.2.6#egg=xblock-poll==1.2.6