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


Python keys.AssetKey类代码示例

本文整理汇总了Python中opaque_keys.edx.keys.AssetKey的典型用法代码示例。如果您正苦于以下问题:Python AssetKey类的具体用法?Python AssetKey怎么用?Python AssetKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: get_location_from_path

 def get_location_from_path(path):
     """
     Generate an AssetKey for the given path (old c4x/org/course/asset/name syntax)
     """
     try:
         return AssetKey.from_string(path)
     except InvalidKeyError:
         # TODO - re-address this once LMS-11198 is tackled.
         if path.startswith('/'):
             # try stripping off the leading slash and try again
             return AssetKey.from_string(path[1:])
开发者ID:B-MOOC,项目名称:edx-platform,代码行数:11,代码来源:content.py

示例2: test_can_delete_signatory

    def test_can_delete_signatory(self, signatory_path):
        """
        Delete an existing certificate signatory
        """
        self._add_course_certificates(count=2, signatory_count=3, asset_path_format=signatory_path)
        certificates = self.course.certificates['certificates']
        signatory = certificates[1].get("signatories")[1]
        image_asset_location = AssetKey.from_string(signatory['signature_image_path'])
        content = contentstore().find(image_asset_location)
        self.assertIsNotNone(content)
        test_url = '{}/signatories/1'.format(self._url(cid=1))
        response = self.client.delete(
            test_url,
            content_type="application/json",
            HTTP_ACCEPT="application/json",
            HTTP_X_REQUESTED_WITH="XMLHttpRequest",
        )
        self.assertEqual(response.status_code, 204)
        self.reload_course()

        # Verify that certificates are properly updated in the course.
        certificates = self.course.certificates['certificates']
        self.assertEqual(len(certificates[1].get("signatories")), 2)
        # make sure signatory signature image is deleted too
        self.assertRaises(NotFoundError, contentstore().find, image_asset_location)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:25,代码来源:test_certificates.py

示例3: test_asset_with_special_character

 def test_asset_with_special_character(self, paths):
     for path in paths:
         asset_locator = AssetKey.from_string(path)
         self.assertEquals(
             path,
             unicode(asset_locator),
         )
开发者ID:mitsei,项目名称:opaque-keys,代码行数:7,代码来源:test_asset_locators.py

示例4: from_xml

 def from_xml(self, node):
     """
     Walk the etree XML node and fill in the asset metadata.
     The node should be a top-level "asset" element.
     """
     for child in node:
         qname = etree.QName(child)
         tag = qname.localname
         if tag in self.ALL_ATTRS:
             value = child.text
             if tag == 'asset_id':
                 # Locator.
                 value = AssetKey.from_string(value)
             elif tag == 'locked':
                 # Boolean.
                 value = True if value == "true" else False
             elif tag in ('created_on', 'edited_on'):
                 # ISO datetime.
                 value = dateutil.parser.parse(value)
             elif tag in ('created_by', 'edited_by'):
                 # Integer representing user id.
                 value = int(value)
             elif tag == 'fields':
                 # Dictionary.
                 value = json.loads(value)
             elif value == 'None':
                 # None.
                 value = None
             setattr(self, tag, value)
开发者ID:Jianbinma,项目名称:edx-platform,代码行数:29,代码来源:__init__.py

示例5: get_asset_key_from_path

    def get_asset_key_from_path(course_key, path):
        """
        Parses a path, extracting an asset key or creating one.

        Args:
            course_key: key to the course which owns this asset
            path: the path to said content

        Returns:
            AssetKey: the asset key that represents the path
        """

        # Clean up the path, removing any static prefix and any leading slash.
        if path.startswith('/static/'):
            path = path[len('/static/'):]

        # Old-style asset keys start with `/`, so don't try and strip it
        # in that case.
        if not path.startswith('/c4x'):
            path = path.lstrip('/')

        try:
            return AssetKey.from_string(path)
        except InvalidKeyError:
            # If we couldn't parse the path, just let compute_location figure it out.
            # It's most likely a path like /image.png or something.
            return StaticContent.compute_location(course_key, path)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:27,代码来源:content.py

示例6: _create_fake_images

 def _create_fake_images(self, asset_keys):
     """
     Creates fake image files for a list of asset_keys.
     """
     for asset_key_string in asset_keys:
         asset_key = AssetKey.from_string(asset_key_string)
         content = StaticContent(asset_key, "Fake asset", "image/png", "data")
         contentstore().save(content)
开发者ID:mjirayu,项目名称:sit_academy,代码行数:8,代码来源:test_certificates.py

示例7: test_replace

 def test_replace(self):
     asset_key = AssetKey.from_string('/c4x/o/c/asset/path')
     self.assertEquals(
         'foo',
         asset_key.replace(path='foo').path
     )
     self.assertEquals(
         'bar',
         asset_key.replace(asset_type='bar').asset_type
     )
开发者ID:bharatmooc,项目名称:opaque-keys,代码行数:10,代码来源:test_asset_locators.py

示例8: get_course_ids_from_link

def get_course_ids_from_link(link):
    """
    Get course Ids from link.

    Arguments:
        link(str): The link to extract course id from.
    Returns:
        Course Ids
    """
    asset_str = link.partition('asset-v1')[1] + link.partition('asset-v1')[2]
    return AssetKey.from_string(asset_str).course_key
开发者ID:edx,项目名称:edx-e2e-tests,代码行数:11,代码来源:redeem_coupon_page.py

示例9: _delete_asset

def _delete_asset(course_key, asset_key_string):
    """
    Internal method used to create asset key from string and
    remove asset by calling delete_asset method of assets module.
    """
    if asset_key_string:
        try:
            asset_key = AssetKey.from_string(asset_key_string)
        except InvalidKeyError:
            # remove first slash in asset path
            # otherwise it generates InvalidKeyError in case of split modulestore
            if '/' == asset_key_string[0]:
                asset_key_string = asset_key_string[1:]
                try:
                    asset_key = AssetKey.from_string(asset_key_string)
                except InvalidKeyError:
                    # Unable to parse the asset key, log and return
                    LOGGER.info(
                        "In course %r, unable to parse asset key %r, not attempting to delete signatory.",
                        course_key,
                        asset_key_string,
                    )
                    return
            else:
                # Unable to parse the asset key, log and return
                LOGGER.info(
                    "In course %r, unable to parse asset key %r, not attempting to delete signatory.",
                    course_key,
                    asset_key_string,
                )
                return

        try:
            delete_asset(course_key, asset_key)
        # If the asset was not found, it doesn't have to be deleted...
        except AssetNotFoundException:
            pass
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:37,代码来源:certificates.py

示例10: _delete_asset

def _delete_asset(course_key, asset_key_string):
    """
    Internal method used to create asset key from string and
    remove asset by calling delete_asset method of assets module.
    """
    if asset_key_string:
        # remove first slash in asset path
        # otherwise it generates InvalidKeyError in case of split modulestore
        if '/' == asset_key_string[0]:
            asset_key_string = asset_key_string[1:]
        asset_key = AssetKey.from_string(asset_key_string)
        try:
            delete_asset(course_key, asset_key)
        # If the asset was not found, it doesn't have to be deleted...
        except AssetNotFoundException:
            pass
开发者ID:sdull,项目名称:edx-platform,代码行数:16,代码来源:certificates.py

示例11: test_get_all_content

    def test_get_all_content(self, deprecated):
        """
        Test get_all_content_for_course
        """
        self.set_up_assets(deprecated)
        course1_assets, count = self.contentstore.get_all_content_for_course(self.course1_key)
        self.assertEqual(count, len(self.course1_files), course1_assets)
        for asset in course1_assets:
            parsed = AssetKey.from_string(asset['filename'])
            self.assertIn(parsed.block_id, self.course1_files)

        course1_assets, __ = self.contentstore.get_all_content_for_course(self.course1_key, 1, 1)
        self.assertEqual(len(course1_assets), 1, course1_assets)

        fake_course = CourseLocator('test', 'fake', 'non')
        course_assets, count = self.contentstore.get_all_content_for_course(fake_course)
        self.assertEqual(count, 0)
        self.assertEqual(course_assets, [])
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:18,代码来源:test_contentstore.py

示例12: copy_all_course_assets

    def copy_all_course_assets(self, source_course_key, dest_course_key):
        """
        See :meth:`.ContentStore.copy_all_course_assets`

        This implementation fairly expensively copies all of the data
        """
        source_query = query_for_course(source_course_key)
        # it'd be great to figure out how to do all of this on the db server and not pull the bits over
        for asset in self.fs_files.find(source_query):
            asset_key = self.make_id_son(asset)
            # don't convert from string until fs access
            source_content = self.fs.get(asset_key)
            if isinstance(asset_key, basestring):
                asset_key = AssetKey.from_string(asset_key)
                __, asset_key = self.asset_db_key(asset_key)
            asset_key["org"] = dest_course_key.org
            asset_key["course"] = dest_course_key.course
            if getattr(dest_course_key, "deprecated", False):  # remove the run if exists
                if "run" in asset_key:
                    del asset_key["run"]
                asset_id = asset_key
            else:  # add the run, since it's the last field, we're golden
                asset_key["run"] = dest_course_key.run
                asset_id = unicode(
                    dest_course_key.make_asset_key(asset_key["category"], asset_key["name"]).for_branch(None)
                )

            self.fs.put(
                source_content.read(),
                _id=asset_id,
                filename=asset["filename"],
                content_type=asset["contentType"],
                displayname=asset["displayname"],
                content_son=asset_key,
                # thumbnail is not technically correct but will be functionally correct as the code
                # only looks at the name which is not course relative.
                thumbnail_location=asset["thumbnail_location"],
                import_path=asset["import_path"],
                # getattr b/c caching may mean some pickled instances don't have attr
                locked=asset.get("locked", False),
            )
开发者ID:sigberto,项目名称:edx-platform,代码行数:41,代码来源:mongo.py

示例13: assets_handler

def assets_handler(request, course_key_string=None, asset_key_string=None):
    '''
    The restful handler for assets.
    It allows retrieval of all the assets (as an HTML page), as well as uploading new assets,
    deleting assets, and changing the 'locked' state of an asset.

    GET
        html: return an html page which will show all course assets. Note that only the asset container
            is returned and that the actual assets are filled in with a client-side request.
        json: returns a page of assets. The following parameters are supported:
            page: the desired page of results (defaults to 0)
            page_size: the number of items per page (defaults to 50)
            sort: the asset field to sort by (defaults to 'date_added')
            direction: the sort direction (defaults to 'descending')
            asset_type: the file type to filter items to (defaults to All)
            text_search: string to filter results by file name (defaults to '')
    POST
        json: create (or update?) an asset. The only updating that can be done is changing the lock state.
    PUT
        json: update the locked state of an asset
    DELETE
        json: delete an asset
    '''
    course_key = CourseKey.from_string(course_key_string)
    if not has_course_author_access(request.user, course_key):
        raise PermissionDenied()

    response_format = _get_response_format(request)
    if _request_response_format_is_json(request, response_format):
        if request.method == 'GET':
            return _assets_json(request, course_key)

        asset_key = AssetKey.from_string(asset_key_string) if asset_key_string else None
        return _update_asset(request, course_key, asset_key)

    elif request.method == 'GET':  # assume html
        return _asset_index(request, course_key)

    return HttpResponseNotFound()
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:39,代码来源:assets.py

示例14: assets_handler

def assets_handler(request, course_key_string=None, asset_key_string=None):
    """
    The restful handler for assets.
    It allows retrieval of all the assets (as an HTML page), as well as uploading new assets,
    deleting assets, and changing the "locked" state of an asset.

    GET
        html: return an html page which will show all course assets. Note that only the asset container
            is returned and that the actual assets are filled in with a client-side request.
        json: returns a page of assets. The following parameters are supported:
            page: the desired page of results (defaults to 0)
            page_size: the number of items per page (defaults to 50)
            sort: the asset field to sort by (defaults to "date_added")
            direction: the sort direction (defaults to "descending")
    POST
        json: create (or update?) an asset. The only updating that can be done is changing the lock state.
    PUT
        json: update the locked state of an asset
    DELETE
        json: delete an asset
    """
    course_key = CourseKey.from_string(course_key_string)
    if not has_course_access(request.user, course_key):
        raise PermissionDenied()

    response_format = request.REQUEST.get('format', 'html')
    if response_format == 'json' or 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'):
        if request.method == 'GET':
            return _assets_json(request, course_key)
        else:
            asset_key = AssetKey.from_string(asset_key_string) if asset_key_string else None
            return _update_asset(request, course_key, asset_key)
    elif request.method == 'GET':  # assume html
        return _asset_index(request, course_key)
    else:
        return HttpResponseNotFound()
开发者ID:AdityaKashyap,项目名称:edx-platform,代码行数:36,代码来源:assets.py

示例15: test_asset_with_trailing_whitespace

 def test_asset_with_trailing_whitespace(self, path_fmt, whitespace):
     with self.assertRaises(InvalidKeyError):
         AssetKey.from_string(path_fmt.format(whitespace))
开发者ID:edx,项目名称:opaque-keys,代码行数:3,代码来源:test_asset_locators.py


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