diff --git a/cms/djangoapps/contentstore/context_processors.py b/cms/djangoapps/contentstore/context_processors.py index 66ba68566148bcb7344b2b27d8924d6ca93d38a2..076b06bde1cd74b4833d71cad0c900911fc3c16c 100644 --- a/cms/djangoapps/contentstore/context_processors.py +++ b/cms/djangoapps/contentstore/context_processors.py @@ -1,4 +1,5 @@ import ConfigParser +from locale import getlocale from django.conf import settings config_file = open(settings.REPO_ROOT / "docs" / "config.ini") @@ -6,15 +7,37 @@ config = ConfigParser.ConfigParser() config.readfp(config_file) -def doc_url(request): - # in the future, we will detect the locale; for now, we will - # hardcode en_us, since we only have English documentation - locale = "en_us" +def doc_url(request=None): - def get_doc_url(token): - try: - return config.get(locale, token) - except ConfigParser.NoOptionError: - return config.get(locale, "default") + def get_online_help_info(page_token): - return {"doc_url": get_doc_url} + def get_config_value(section_name, key, default_key="default"): + try: + return config.get(section_name, key) + except (ConfigParser.NoOptionError, AttributeError): + return config.get(section_name, default_key) + + def get_page_path(page_token): + return get_config_value("pages", page_token) + + def get_langage_path(request): + language_code = settings.LANGUAGE_CODE + return get_config_value("locales", language_code) + + def get_url(base_option): + return "{base_url}/{language}/{version}/{page_path}".format( + base_url=config.get("server_settings", base_option), + language=language_dir, + version=config.get("server_settings", "version"), + page_path=page_path, + ) + + language_dir = get_langage_path(request) + page_path = get_page_path(page_token) + + return { + "doc_url": get_url("base_url"), + "pdf_url": get_url("base_pdf"), + } + + return {'get_online_help_info': get_online_help_info} diff --git a/cms/templates/base.html b/cms/templates/base.html index 93a3ec4ff7f6ec75f8219011b6d95235ff95e7ce..75b94fe32e99bf209bf419214ffe5741066df665 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -264,7 +264,8 @@ <!-- view --> <div class="wrapper wrapper-view"> - <%include file="widgets/header.html" /> + <% online_help_token = self.online_help_token() if hasattr(self, 'online_help_token') else None %> + <%include file="widgets/header.html" args="online_help_token=online_help_token" /> <div id="page-alert"></div> diff --git a/cms/templates/edit-tabs.html b/cms/templates/edit-tabs.html index 2c0c964508c964d2ea7234bdc2d3d4f6298b7190..76ae27e2681d959eb71e2d493c7b8f3553975356 100644 --- a/cms/templates/edit-tabs.html +++ b/cms/templates/edit-tabs.html @@ -1,4 +1,5 @@ <%inherit file="base.html" /> +<%def name="online_help_token()"><% return "pages" %></%def> <%namespace name='static' file='static_content.html'/> <%! from django.utils.translation import ugettext as _ diff --git a/cms/templates/textbooks.html b/cms/templates/textbooks.html index 09267faef596d9de05c2db7066f586e29b224098..12c40ef6cdf099b99851ee131a7648781f0c0e2c 100644 --- a/cms/templates/textbooks.html +++ b/cms/templates/textbooks.html @@ -1,4 +1,5 @@ <%inherit file="base.html" /> +<%def name="online_help_token()"><% return "textbooks" %></%def> <%namespace name='static' file='static_content.html'/> <%! import json %> <%! from django.utils.translation import ugettext as _ %> diff --git a/cms/templates/widgets/header.html b/cms/templates/widgets/header.html index f27d5b9ea9df95f3e9827f780cc3bd1326c68d35..0e87a63c482e99359f634b10ac937cb198b7aad9 100644 --- a/cms/templates/widgets/header.html +++ b/cms/templates/widgets/header.html @@ -3,7 +3,9 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ from xmodule.modulestore.django import loc_mapper + from contentstore.context_processors import doc_url %> +<%page args="online_help_token"/> <div class="wrapper-header wrapper" id="view-top"> <header class="primary" role="banner"> @@ -123,6 +125,10 @@ <nav class="nav-account nav-is-signedin nav-dd ui-right"> <h2 class="sr">${_("Help & Account Navigation")}</h2> + <% + help_doc_urls = get_online_help_info(online_help_token) + %> + <ol> <li class="nav-item nav-account-help"> <h3 class="title"><span class="label">${_("Help")}</span> <i class="icon-caret-down ui-toggle-dd"></i></h3> @@ -131,7 +137,7 @@ <div class="nav-sub"> <ul> <li class="nav-item nav-help-documentation"> - <a href="http://files.edx.org/Getting_Started_with_Studio.pdf" title="${_("This is a PDF Document")}">${_("Studio Documentation")}</a> + <a href="${help_doc_urls['pdf_url']}" title="${_("This is a PDF Document")}">${_("Studio Documentation")}</a> </li> <li class="nav-item nav-help-helpcenter"> <a href="http://help.edge.edx.org/" rel="external">${_("Studio Help Center")}</a> @@ -139,6 +145,11 @@ <li class="nav-item nav-help-feedback"> <a href="http://help.edge.edx.org/discussion/new" class="show-tender" title="${_("Use our feedback tool, Tender, to share your feedback")}">${_("Contact Us")}</a> </li> + % if online_help_token: + <li class="nav-item nav-help-online"> + <a href="${help_doc_urls['doc_url']}" title="${_("Contextual Online Help")}">${_("Online Help")}</a> + </li> + % endif </ul> </div> </div> diff --git a/docs/config.ini b/docs/config.ini index 6337e350dec144bd7440d37a9192457e775f6d1e..a0b0050327d55fe0bc0ea0060d78f05f27ff0a40 100644 --- a/docs/config.ini +++ b/docs/config.ini @@ -1,2 +1,29 @@ -[en_us] -default=default +# below are the server-wide settings for documentation +[server_settings] +base_url = http://edx.readthedocs.org/projects/edx-partner-course-staff +base_pdf = https://media.readthedocs.org/pdf/edx-partner-course-staff +version = latest + +# below are the sub-paths to the documentation for the various pages +[pages] +default = index.html +home = getting_started/get_started.html +courses = building_course/creating_new_course.html +outline = creating_content/organizing_course.html +updates = creating_content/handouts_updates.html +pages = creating_content/pages.html +files = creating_content/course_files.html +textbooks = creating_content/textbooks.html +schedule = building_course/setting_up_student_view.html +grading = building_course/establish_grading_policy.html +team = building_course/creating_new_course.html#add-course-team-members +advanced = index.html +checklist = building_course/creating_new_course.html#use-the-course-checklist +import = building_course/export_import_course.html +export = building_course/export_import_course.html + +# below are the language directory names for the different locales +[locales] +default = en +en = en +en_us = en