本文整理汇总了Python中contentstore.course_group_config.GroupConfiguration.get_partitions_usage_info方法的典型用法代码示例。如果您正苦于以下问题:Python GroupConfiguration.get_partitions_usage_info方法的具体用法?Python GroupConfiguration.get_partitions_usage_info怎么用?Python GroupConfiguration.get_partitions_usage_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contentstore.course_group_config.GroupConfiguration
的用法示例。
在下文中一共展示了GroupConfiguration.get_partitions_usage_info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_group_usage
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_partitions_usage_info [as 别名]
def fetch_group_usage(cls, modulestore, structure):
groups_usage_dict = {}
partitions_info = GroupConfiguration.get_partitions_usage_info(modulestore, structure)
content_group_info = GroupConfiguration.get_content_groups_items_usage_info(
modulestore,
structure
)
for group_info in (partitions_info, content_group_info):
for groups in group_info.values():
for name, group in groups.items():
for module in group:
view, args, kwargs = resolve(module['url']) # pylint: disable=unused-variable
usage_key_string = unicode(kwargs['usage_key_string'])
if groups_usage_dict.get(usage_key_string, None):
groups_usage_dict[usage_key_string].append(name)
else:
groups_usage_dict[usage_key_string] = [name]
return groups_usage_dict
示例2: test_can_handle_multiple_partitions
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_partitions_usage_info [as 别名]
def test_can_handle_multiple_partitions(self):
# Create the user partitions
self.course.user_partitions = [
UserPartition(
id=0,
name='Cohort user partition',
scheme=UserPartition.get_scheme('cohort'),
description='Cohorted user partition',
groups=[
Group(id=0, name="Group A"),
Group(id=1, name="Group B"),
],
),
UserPartition(
id=1,
name='Random user partition',
scheme=UserPartition.get_scheme('random'),
description='Random user partition',
groups=[
Group(id=0, name="Group A"),
Group(id=1, name="Group B"),
],
),
]
self.store.update_item(self.course, ModuleStoreEnum.UserID.test)
# Assign group access rules for multiple partitions, one of which is a cohorted partition
__, problem = self._create_problem_with_content_group(0, 1)
problem.group_access = {
0: [0],
1: [1],
}
self.store.update_item(problem, ModuleStoreEnum.UserID.test)
# This used to cause an exception since the code assumed that
# only one partition would be available.
actual = GroupConfiguration.get_partitions_usage_info(self.store, self.course)
self.assertEqual(actual.keys(), [0])
actual = GroupConfiguration.get_content_groups_items_usage_info(self.store, self.course)
self.assertEqual(actual.keys(), [0])
示例3: test_can_handle_duplicate_group_ids
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_partitions_usage_info [as 别名]
def test_can_handle_duplicate_group_ids(self):
# Create the user partitions
self.course.user_partitions = [
UserPartition(
id=0,
name='Cohort user partition 1',
scheme=UserPartition.get_scheme('cohort'),
description='Cohorted user partition',
groups=[
Group(id=2, name="Group 1A"),
Group(id=3, name="Group 1B"),
],
),
UserPartition(
id=1,
name='Cohort user partition 2',
scheme=UserPartition.get_scheme('cohort'),
description='Random user partition',
groups=[
Group(id=2, name="Group 2A"),
Group(id=3, name="Group 2B"),
],
),
]
self.store.update_item(self.course, ModuleStoreEnum.UserID.test)
# Assign group access rules for multiple partitions, one of which is a cohorted partition
self._create_problem_with_content_group(0, 2, name_suffix='0')
self._create_problem_with_content_group(1, 3, name_suffix='1')
# This used to cause an exception since the code assumed that
# only one partition would be available.
actual = GroupConfiguration.get_partitions_usage_info(self.store, self.course)
self.assertEqual(actual.keys(), [0, 1])
self.assertEqual(actual[0].keys(), [2])
self.assertEqual(actual[1].keys(), [3])
actual = GroupConfiguration.get_content_groups_items_usage_info(self.store, self.course)
self.assertEqual(actual.keys(), [0, 1])
self.assertEqual(actual[0].keys(), [2])
self.assertEqual(actual[1].keys(), [3])
示例4: handle
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_partitions_usage_info [as 别名]
#.........这里部分代码省略.........
print "Queueing XBlock at location: '%s' for Audit Content Group update " % item.location
set_audit_enrollment_track = True
# Check the partition and group IDs for the verified course group, if it exists in
# the xblock's access settings then set the verified track flag to true
verified_partition_group_access = item.group_access.get(
verified_course_user_group_partition_group.partition_id,
None
)
if verified_partition_group_access:
non_verified_track_access_groups = (set(verified_partition_group_access) -
all_cohorted_track_group_ids)
# If the item has group_access that is not the
# verified or audit group IDs then raise an error
# This only needs to be checked for this partition_group once
if non_verified_track_access_groups:
errors.append(
"Non audit/verified cohorted content group set for xblock, location '%s' with IDs '%s'"
% (item.location, non_verified_track_access_groups)
)
if verified_course_user_group_partition_group.group_id in verified_partition_group_access:
print "Queueing XBlock at location: '%s' for Verified Content Group update " % item.location
set_verified_enrollment_track = True
# Add the enrollment track ids to a group access array
enrollment_track_group_access = []
if set_audit_enrollment_track:
enrollment_track_group_access.append(settings.COURSE_ENROLLMENT_MODES['audit'])
if set_verified_enrollment_track:
enrollment_track_group_access.append(settings.COURSE_ENROLLMENT_MODES['verified'])
# If there are no errors, and either the audit track, or verified
# track needed an update, set the access, update and publish
if set_verified_enrollment_track or set_audit_enrollment_track:
# Sets whether or not an xblock has changes
has_changes = module_store.has_changes(item)
# Check that the xblock does not have changes and add it to be updated, otherwise add an error
if not has_changes:
item.group_access = {ENROLLMENT_TRACK_PARTITION_ID: enrollment_track_group_access}
items_to_update.append(item)
else:
errors.append("XBlock '%s' with location '%s' needs access changes, but is a draft"
% (item.display_name, item.location))
partitions_to_delete = random_audit_course_user_group_partition_groups
partitions_to_delete.append(verified_course_user_group_partition_group)
# If there are no errors iterate over and update all of the items that had the access changed
if not errors:
for item in items_to_update:
module_store.update_item(item, ModuleStoreEnum.UserID.mgmt_command)
module_store.publish(item.location, ModuleStoreEnum.UserID.mgmt_command)
print "Updated and published XBlock at location: '%s'" % item.location
# Check if we should delete any partition groups if there are no errors.
# If there are errors, none of the xblock items will have been updated,
# so this section will throw errors for each partition in use
if partitions_to_delete and not errors:
partition_service = PartitionService(rerun_course_key)
course = partition_service.get_course()
for partition_to_delete in partitions_to_delete:
# Get the user partition, and the index of that partition in the course
partition = partition_service.get_user_partition(partition_to_delete.partition_id)
if partition:
partition_index = course.user_partitions.index(partition)
group_id = int(partition_to_delete.group_id)
# Sanity check to verify that all of the groups being deleted are empty,
# since they should have been converted to use enrollment tracks instead.
# Taken from contentstore/views/course.py.remove_content_or_experiment_group
usages = GroupConfiguration.get_partitions_usage_info(module_store, course)
used = group_id in usages
if used:
errors.append("Content group '%s' is in use and cannot be deleted."
% partition_to_delete.group_id)
# If there are not errors, proceed to update the course and user_partitions
if not errors:
# Remove the groups that match the group ID of the partition to be deleted
# Else if there are no match groups left, remove the user partition
matching_groups = [group for group in partition.groups if group.id == group_id]
if matching_groups:
group_index = partition.groups.index(matching_groups[0])
partition.groups.pop(group_index)
# Update the course user partition with the updated groups
if partition.groups:
course.user_partitions[partition_index] = partition
else:
course.user_partitions.pop(partition_index)
module_store.update_item(course, ModuleStoreEnum.UserID.mgmt_command)
# If there are any errors, join them together and raise the CommandError
if errors:
raise CommandError(
("Error for MigrateVerifiedTrackCohortsSetting with ID='%s'\n" % verified_track_cohorts_setting.id) +
"\t\n".join(errors)
)
print "Finished for MigrateVerifiedTrackCohortsSetting with ID='%s" % verified_track_cohorts_setting.id