本文整理汇总了Python中contentstore.course_group_config.GroupConfiguration.get_or_create_content_group方法的典型用法代码示例。如果您正苦于以下问题:Python GroupConfiguration.get_or_create_content_group方法的具体用法?Python GroupConfiguration.get_or_create_content_group怎么用?Python GroupConfiguration.get_or_create_content_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contentstore.course_group_config.GroupConfiguration
的用法示例。
在下文中一共展示了GroupConfiguration.get_or_create_content_group方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_content_group_not_used
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def test_content_group_not_used(self):
"""
Test that right data structure will be created if content group is not used.
"""
self._add_user_partitions(scheme_id='cohort')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[])
self.assertEqual(actual, expected)
示例2: val_items_visibility_by_group
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def val_items_visibility_by_group(self):
"""Составление таблицы видимости элементов для групп"""
with self.store.bulk_operations(self.course_key):
course = self.course
content_group_configuration = GroupConfiguration.get_or_create_content_group(self.store, course)
groups = content_group_configuration["groups"]
group_names = [g["name"] for g in groups]
head = [_("Item type"), _("Usual student")] + group_names
visibility_by_group_categories = self.visibility_by_group_categories
get_items_by_type = lambda x: [y for y in self.items if y.category == x]
# Словарь (категория - итемы)
cat_items = dict([(c, get_items_by_type(c)) for c in visibility_by_group_categories])
# Словарь id группы - название группы
group_id_dict = dict([(g["id"], g["name"]) for g in groups])
conf_id = content_group_configuration["id"]
group_visible_strs = []
for cat in visibility_by_group_categories:
items = cat_items[cat]
vis = dict((g, 0) for g in group_names)
vis["student"] = 0
for it in items:
if conf_id not in it.group_access:
for key in group_names:
vis[key] += 1
else:
ids = it.group_access[conf_id]
item_vis_for_groups = [group_id_dict[i] for i in ids]
for group in item_vis_for_groups:
vis[group] += 1
if not it.visible_to_staff_only:
vis["student"] += 1
item_category = "{}({})".format(cat, len(items))
stud_vis_for_cat = str(vis["student"])
cat_list = [item_category] + [stud_vis_for_cat] + [str(vis[gn]) for gn in group_names]
cat_str = cat_list
group_visible_strs.append(cat_str)
return Report(name=self.scenarios_names["items_visibility_by_group"],
head=head,
body=group_visible_strs,
warnings=[]
)
示例3: test_can_get_correct_usage_info_for_content_groups
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def test_can_get_correct_usage_info_for_content_groups(self):
"""
Test if content group json updated successfully with usage information.
"""
self._add_user_partitions(count=1, scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[
{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Problem 0'
}
])
self.assertEqual(actual, expected)
示例4: val_group
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def val_group(self):
"""Проверка наличия и использования в курсе групп"""
with self.store.bulk_operations(self.course_key):
course = self.course
content_group_configuration = GroupConfiguration.get_or_create_content_group(self.store, course)
groups = content_group_configuration["groups"]
is_group_used = lambda x: bool(len(x["usage"]))
# запись для каждой группы ее использования
group_strs = [[g["name"], str(is_group_used(g))] for g in groups]
head = [_("Group name"), _("Group used")]
results = Report(name=self.scenarios_names["group"],
head=head,
body=group_strs,
warnings=[],
)
return results
示例5: test_can_use_one_content_group_in_multiple_problems
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def test_can_use_one_content_group_in_multiple_problems(self):
"""
Test if multiple problems are present in usage info when they use same
content group.
"""
self._add_user_partitions(scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
vertical1, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='1')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[
{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Problem 0'
},
{
'url': '/container/{}'.format(vertical1.location),
'label': 'Test Unit 1 / Test Problem 1'
}
])
self.assertEqual(actual, expected)
示例6: test_can_get_correct_usage_info_with_orphan
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def test_can_get_correct_usage_info_with_orphan(self, module_store_type):
"""
Test if content group json updated successfully with usage information even if there is
an orphan in content group.
"""
self.course = CourseFactory.create(default_store=module_store_type)
self._add_user_partitions(count=1, scheme_id='cohort')
vertical, problem = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
# Assert that there is no orphan in the course yet.
self.assertEqual(len(self.store.get_orphans(self.course.id)), 0)
# Update problem(created earlier) to an orphan.
with self.store.branch_setting(ModuleStoreEnum.Branch.published_only):
vertical = self.store.get_item(vertical.location)
vertical.children.remove(problem.location)
self.store.update_item(vertical, self.user.id)
# Assert that the problem is orphan now.
self.assertIn(problem.location, self.store.get_orphans(self.course.id))
# Get the expected content group information based on module store.
if module_store_type == ModuleStoreEnum.Type.mongo:
expected = self._get_expected_content_group(usage_for_group=[
{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Problem 0'
}
])
else:
expected = self._get_expected_content_group(usage_for_group=[])
# Get the actual content group information
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
# Assert that actual content group information is same as expected one.
self.assertEqual(actual, expected)
示例7: val_openassessment
# 需要导入模块: from contentstore.course_group_config import GroupConfiguration [as 别名]
# 或者: from contentstore.course_group_config.GroupConfiguration import get_or_create_content_group [as 别名]
def val_openassessment(self):
head = [_("Name"), _("Location"), _("Publishing date"), _("Submission start"), _("Submission due"),
_("Peer start"), _("Peer due"), _("Cohorts where visible"),
_("Assessment steps")]
openassessments = [i for i in self.items if i.category == "openassessment"]
additional_info = {}
body = []
with self.store.bulk_operations(self.course_key):
course = self.course
content_group_configuration = GroupConfiguration.get_or_create_content_group(self.store, course)
groups = content_group_configuration["groups"]
conf_id = content_group_configuration["id"]
group_id_dict = dict([(g["id"], g["name"]) for g in groups])
unicode2date = lambda x: datetime.strptime(x.split('+')[0], '%Y-%m-%dT%H:%M:%S')
date2str = lambda x: x.strftime("%d.%m.%Y, %H:%M")
for num, oa in enumerate(openassessments):
url_key = (num, 0)
additional_info[url_key] = reverse_usage_url("container_handler", oa.location)
current = []
name = oa.display_name
current.append(name)
parent = oa.get_parent()
location = u"{}, {}".format(parent.display_name, parent.get_parent().display_name)
current.append(location)
publish_date = oa.published_on
if publish_date:
current.append(date2str(publish_date))
else:
current.append(_("Not published"))
submission_start = unicode2date(oa.submission_start)
current.append(date2str(submission_start))
submission_due = unicode2date(oa.submission_due)
current.append(date2str(submission_due))
peer_start = unicode2date(oa.rubric_assessments[1]["start"])
current.append(date2str(peer_start))
peer_due = unicode2date(oa.rubric_assessments[1]["due"])
current.append(date2str(peer_due))
if conf_id in oa.group_access:
accessed = oa.group_access[conf_id]
visible_groups = u", ".join(group_id_dict[i] for i in accessed)
else:
visible_groups = _("Usual student")
current.append(visible_groups)
steps = oa.assessment_steps
current.append(u",".join(str(s) for s in range(1, len(steps) + 1)))
body.append(current)
self.additional_info.update({self.scenarios_names["openassessment"]: additional_info})
return Report(name=self.scenarios_names["openassessment"],
head=head,
body=body,
warnings=[]
)