当前位置: 首页>>代码示例>>Python>>正文


Python CourseMetadata.delete_key方法代码示例

本文整理汇总了Python中models.settings.course_metadata.CourseMetadata.delete_key方法的典型用法代码示例。如果您正苦于以下问题:Python CourseMetadata.delete_key方法的具体用法?Python CourseMetadata.delete_key怎么用?Python CourseMetadata.delete_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.settings.course_metadata.CourseMetadata的用法示例。


在下文中一共展示了CourseMetadata.delete_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete_key

# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import delete_key [as 别名]
 def test_delete_key(self):
     test_model = CourseMetadata.delete_key(self.fullcourse_location, {'deleteKeys': ['doesnt_exist', 'showanswer', 'xqa_key']})
     # ensure no harm
     self.assertNotIn('graceperiod', test_model, 'blacklisted field leaked in')
     self.assertIn('display_name', test_model, 'full missing editable metadata field')
     self.assertEqual(test_model['display_name'], 'Robot Super Course', "not expected value")
     self.assertIn('rerandomize', test_model, 'Missing rerandomize metadata field')
     # check for deletion effectiveness
     self.assertEqual('finished', test_model['showanswer'], 'showanswer field still in')
     self.assertEqual(None, test_model['xqa_key'], 'xqa_key field still in')
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:12,代码来源:test_course_settings.py

示例2: test_delete_key

# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import delete_key [as 别名]
 def test_delete_key(self):
     test_model = CourseMetadata.delete_key(
         self.fullcourse_location, {"deleteKeys": ["doesnt_exist", "showanswer", "xqa_key"]}
     )
     # ensure no harm
     self.assertNotIn("graceperiod", test_model, "blacklisted field leaked in")
     self.assertIn("display_name", test_model, "full missing editable metadata field")
     self.assertEqual(test_model["display_name"], "Robot Super Course", "not expected value")
     self.assertIn("rerandomize", test_model, "Missing rerandomize metadata field")
     # check for deletion effectiveness
     self.assertEqual("finished", test_model["showanswer"], "showanswer field still in")
     self.assertEqual(None, test_model["xqa_key"], "xqa_key field still in")
开发者ID:rajeshpillai,项目名称:edx-platform,代码行数:14,代码来源:test_course_settings.py

示例3: course_advanced_updates

# 需要导入模块: from models.settings.course_metadata import CourseMetadata [as 别名]
# 或者: from models.settings.course_metadata.CourseMetadata import delete_key [as 别名]
def course_advanced_updates(request, org, course, name):
    """
    restful CRUD operations on metadata. The payload is a json rep of the metadata dicts. For delete, otoh,
    the payload is either a key or a list of keys to delete.

    org, course: Attributes of the Location for the item to edit
    """
    location = get_location_and_verify_access(request, org, course, name)

    real_method = get_request_method(request)

    if real_method == 'GET':
        return HttpResponse(json.dumps(CourseMetadata.fetch(location)),
                            mimetype="application/json")
    elif real_method == 'DELETE':
        return HttpResponse(json.dumps(CourseMetadata.delete_key(location,
                                                                 json.loads(request.body))),
                            mimetype="application/json")
    elif real_method == 'POST' or real_method == 'PUT':
        # NOTE: request.POST is messed up because expect_json
        # cloned_request.POST.copy() is creating a defective entry w/ the whole payload as the key
        request_body = json.loads(request.body)
        # Whether or not to filter the tabs key out of the settings metadata
        filter_tabs = True

        # Check to see if the user instantiated any advanced components. This is a hack
        # that does the following :
        #   1) adds/removes the open ended panel tab to a course automatically if the user
        #   has indicated that they want to edit the combinedopendended or peergrading module
        #   2) adds/removes the notes panel tab to a course automatically if the user has
        #   indicated that they want the notes module enabled in their course
        # TODO refactor the above into distinct advanced policy settings
        if ADVANCED_COMPONENT_POLICY_KEY in request_body:
            # Get the course so that we can scrape current tabs
            course_module = modulestore().get_item(location)

            # Maps tab types to components
            tab_component_map = {
                'open_ended': OPEN_ENDED_COMPONENT_TYPES,
                'notes': NOTE_COMPONENT_TYPES,
            }

            # Check to see if the user instantiated any notes or open ended components
            for tab_type in tab_component_map.keys():
                component_types = tab_component_map.get(tab_type)
                found_ac_type = False
                for ac_type in component_types:
                    if ac_type in request_body[ADVANCED_COMPONENT_POLICY_KEY]:
                        # Add tab to the course if needed
                        changed, new_tabs = add_extra_panel_tab(tab_type, course_module)
                        # If a tab has been added to the course, then send the metadata along to CourseMetadata.update_from_json
                        if changed:
                            course_module.tabs = new_tabs
                            request_body.update({'tabs': new_tabs})
                            # Indicate that tabs should not be filtered out of the metadata
                            filter_tabs = False
                        # Set this flag to avoid the tab removal code below.
                        found_ac_type = True
                        break
                # If we did not find a module type in the advanced settings,
                # we may need to remove the tab from the course.
                if not found_ac_type:
                    # Remove tab from the course if needed
                    changed, new_tabs = remove_extra_panel_tab(tab_type, course_module)
                    if changed:
                        course_module.tabs = new_tabs
                        request_body.update({'tabs': new_tabs})
                        # Indicate that tabs should *not* be filtered out of the metadata
                        filter_tabs = False
        try:
            response_json = json.dumps(CourseMetadata.update_from_json(location,
                                                                   request_body,
                                                                   filter_tabs=filter_tabs))
        except (TypeError, ValueError), e:
            return HttpResponseBadRequest("Incorrect setting format. " + str(e), content_type="text/plain")

        return HttpResponse(response_json, mimetype="application/json")
开发者ID:bizdict,项目名称:edx-platform,代码行数:79,代码来源:course.py


注:本文中的models.settings.course_metadata.CourseMetadata.delete_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。