From a88bb7caf3b09d87ab57c976d732ca75246d8f32 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 17 Oct 2012 16:08:16 -0400 Subject: [PATCH 1/2] hide 'View Live' button if no units have been published --- cms/djangoapps/contentstore/views.py | 12 ++++++++++-- cms/templates/edit_subsection.html | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 28b1742621..638db228cd 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -55,7 +55,7 @@ from cache_toolbox.core import set_cached_content, get_cached_content, del_cache from auth.authz import is_user_in_course_group_role, get_users_in_course_group_by_role from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_from_course_group from auth.authz import INSTRUCTOR_ROLE_NAME, STAFF_ROLE_NAME, create_all_course_groups -from .utils import get_course_location_for_item, get_lms_link_for_item, compute_unit_state, get_date_display +from .utils import get_course_location_for_item, get_lms_link_for_item, compute_unit_state, get_date_display, UnitState from xmodule.templates import all_templates from xmodule.modulestore.xml_importer import import_from_xml @@ -214,6 +214,13 @@ def edit_subsection(request, location): policy_metadata = dict((key,value) for key, value in item.metadata.iteritems() if key not in ['display_name', 'start', 'due', 'format'] and key not in item.system_metadata_fields) + can_view_live = False + for unit in item.get_children(): + state = compute_unit_state(unit) + if state == UnitState.public or state == UnitState.draft: + can_view_live = True + break + return render_to_response('edit_subsection.html', {'subsection': item, 'context_course': course, @@ -221,7 +228,8 @@ def edit_subsection(request, location): 'lms_link': lms_link, 'preview_link': preview_link, 'parent_item': parent, - 'policy_metadata' : policy_metadata + 'policy_metadata' : policy_metadata, + 'can_view_live' : can_view_live }) diff --git a/cms/templates/edit_subsection.html b/cms/templates/edit_subsection.html index 15753e9720..4eb8210816 100644 --- a/cms/templates/edit_subsection.html +++ b/cms/templates/edit_subsection.html @@ -95,7 +95,9 @@
Save Preview Drafts + %if can_view_live: View Live + %endif
From 1a6845b07fcea7b474243956c58aa87350ecff57 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 17 Oct 2012 16:17:52 -0400 Subject: [PATCH 2/2] optimize slightly, allow caller to pass in the list of units in a subsection, so we don't have to refetch --- cms/djangoapps/contentstore/views.py | 4 +++- cms/templates/edit_subsection.html | 2 +- cms/templates/widgets/units.html | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 638db228cd..1f206539f3 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -215,7 +215,8 @@ def edit_subsection(request, location): if key not in ['display_name', 'start', 'due', 'format'] and key not in item.system_metadata_fields) can_view_live = False - for unit in item.get_children(): + subsection_units = item.get_children() + for unit in subsection_units: state = compute_unit_state(unit) if state == UnitState.public or state == UnitState.draft: can_view_live = True @@ -229,6 +230,7 @@ def edit_subsection(request, location): 'preview_link': preview_link, 'parent_item': parent, 'policy_metadata' : policy_metadata, + 'subsection_units' : subsection_units, 'can_view_live' : can_view_live }) diff --git a/cms/templates/edit_subsection.html b/cms/templates/edit_subsection.html index 4eb8210816..4c2a7d7516 100644 --- a/cms/templates/edit_subsection.html +++ b/cms/templates/edit_subsection.html @@ -29,7 +29,7 @@
- ${units.enum_units(subsection)} + ${units.enum_units(subsection, subsection_units=subsection_units)}
diff --git a/cms/templates/widgets/units.html b/cms/templates/widgets/units.html index fe955baafe..df632ac3d8 100644 --- a/cms/templates/widgets/units.html +++ b/cms/templates/widgets/units.html @@ -4,9 +4,13 @@ -<%def name="enum_units(subsection, actions=True, selected=None, sortable=True)"> +<%def name="enum_units(subsection, actions=True, selected=None, sortable=True, subsection_units=None)">
    - % for unit in subsection.get_children(): + <% + if subsection_units is None: + subsection_units = subsection.get_children() + %> + % for unit in subsection_units:
  1. <% unit_state = compute_unit_state(unit)