From 2671801f93529f18e6a84e783d84417b5ef1291b Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Thu, 26 Jul 2012 14:55:42 -0400 Subject: [PATCH 1/2] Add optional hide_from_toc attribute to XML elements to support Tutorials (which don't show up in the navigation). --- common/lib/xmodule/xmodule/x_module.py | 3 ++- common/lib/xmodule/xmodule/xml_module.py | 2 +- lms/djangoapps/courseware/module_render.py | 4 ++- lms/templates/accordion.html | 30 ++++++++++++---------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 7fd0b04f94..996d31a83d 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -104,7 +104,8 @@ class HTMLSnippet(object): """ Return the html used to display this snippet """ - raise NotImplementedError("get_html() must be provided by specific modules") + raise NotImplementedError("get_html() must be provided by specific modules - not present in {0}" + .format(self.__class__)) class XModule(HTMLSnippet): diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index eeceeb3c1c..a7fc686e45 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -88,7 +88,7 @@ class XmlDescriptor(XModuleDescriptor): # The attributes will be removed from the definition xml passed # to definition_from_xml, and from the xml returned by definition_to_xml metadata_attributes = ('format', 'graceperiod', 'showanswer', 'rerandomize', - 'start', 'due', 'graded', 'name', 'slug') + 'start', 'due', 'graded', 'name', 'slug', 'hide_from_toc') # A dictionary mapping xml attribute names to functions of the value # that return the metadata key and value diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 3f111c2953..0a089af33b 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -56,11 +56,13 @@ def toc_for_course(user, request, course, active_chapter, active_section): active = (chapter.metadata.get('display_name') == active_chapter and section.metadata.get('display_name') == active_section) + hide_from_toc = section.metadata.get('hide_from_toc', 'false').lower() == 'true' sections.append({'name': section.metadata.get('display_name'), 'format': section.metadata.get('format', ''), 'due': section.metadata.get('due', ''), - 'active': active}) + 'active': active, + 'hide_from_toc' : hide_from_toc}) chapters.append({'name': chapter.metadata.get('display_name'), 'sections': sections, diff --git a/lms/templates/accordion.html b/lms/templates/accordion.html index d9e6cee61e..f67126c614 100644 --- a/lms/templates/accordion.html +++ b/lms/templates/accordion.html @@ -3,20 +3,22 @@ <%def name="make_chapter(chapter)">

${chapter['name']}

- - + + % for chapter in toc: ${make_chapter(chapter)} From 72341569f9ade8ba0caf423ec6cccaf019a42059 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 27 Jul 2012 01:22:07 -0400 Subject: [PATCH 2/2] Remove sections from ever getting appended in the first place if hide_from_toc is true --- lms/djangoapps/courseware/module_render.py | 10 +++++----- lms/templates/accordion.html | 20 +++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 0a089af33b..01e46b8def 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -58,11 +58,11 @@ def toc_for_course(user, request, course, active_chapter, active_section): section.metadata.get('display_name') == active_section) hide_from_toc = section.metadata.get('hide_from_toc', 'false').lower() == 'true' - sections.append({'name': section.metadata.get('display_name'), - 'format': section.metadata.get('format', ''), - 'due': section.metadata.get('due', ''), - 'active': active, - 'hide_from_toc' : hide_from_toc}) + if not hide_from_toc: + sections.append({'name': section.metadata.get('display_name'), + 'format': section.metadata.get('format', ''), + 'due': section.metadata.get('due', ''), + 'active': active}) chapters.append({'name': chapter.metadata.get('display_name'), 'sections': sections, diff --git a/lms/templates/accordion.html b/lms/templates/accordion.html index f67126c614..defb424a29 100644 --- a/lms/templates/accordion.html +++ b/lms/templates/accordion.html @@ -5,17 +5,15 @@