From 6b9f853ccfadf6cee263eff05bf1db3951fe44e3 Mon Sep 17 00:00:00 2001 From: Mushtaq Ali Date: Wed, 22 Mar 2017 15:19:59 +0500 Subject: [PATCH] make matching group ID condition be more specific --- cms/djangoapps/contentstore/utils.py | 14 +++++++------- cms/djangoapps/contentstore/views/item.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index f1a5ed1494..70a1d43740 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -283,20 +283,20 @@ def reverse_usage_url(handler_name, usage_key, kwargs=None): return reverse_url(handler_name, 'usage_key_string', usage_key, kwargs) -def get_group_display_name(user_partitions, xblock_display_name): +def get_split_group_display_name(xblock, course): """ - Get the group name if matching group xblock is found. + Returns group name if an xblock is found in user partition groups that are suitable for the split_test module. Arguments: - user_partitions (Dict): Locator of source item. - xblock_display_name (String): Display name of group xblock. + xblock (XBlock): The courseware component. + course (XBlock): The course descriptor. Returns: - group name (String): Group name of the matching group. + group name (String): Group name of the matching group xblock. """ - for user_partition in user_partitions: + for user_partition in get_user_partition_info(xblock, schemes=['random'], course=course): for group in user_partition['groups']: - if str(group['id']) in xblock_display_name: + if 'Group ID {group_id}'.format(group_id=group['id']) == xblock.display_name_with_default: return group['name'] diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index d5e2f7febf..5e6eeac1ac 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -29,7 +29,7 @@ from cms.lib.xblock.authoring_mixin import VISIBILITY_VIEW from contentstore.utils import ( find_release_date_source, find_staff_lock_source, is_currently_visible_to_students, ancestor_has_staff_lock, has_children_visible_to_specific_content_groups, - get_user_partition_info, get_group_display_name, + get_user_partition_info, get_split_group_display_name, ) from contentstore.views.helpers import is_unit, xblock_studio_url, xblock_primary_child_category, \ xblock_type_display_name, get_parent_xblock, create_xblock, usage_key_with_run @@ -1125,7 +1125,6 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F # a percent value out of 100, e.g. "58%" means "58/100". pct_sign=_('%')) - user_partitions = get_user_partition_info(xblock, course=course) xblock_info = { 'id': unicode(xblock.location), 'display_name': xblock.display_name_with_default, @@ -1136,9 +1135,10 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F if child_info and len(child_info.get('children', [])) > 0: xblock_info['child_info'] = child_info # Groups are labelled with their internal ids, rather than with the group name. Replace id with display name. - group_display_name = get_group_display_name(user_partitions, xblock_info['display_name']) + group_display_name = get_split_group_display_name(xblock, course) xblock_info['display_name'] = group_display_name if group_display_name else xblock_info['display_name'] else: + user_partitions = get_user_partition_info(xblock, course=course) xblock_info.update({ 'edited_on': get_default_time_display(xblock.subtree_edited_on) if xblock.subtree_edited_on else None, 'published': published,