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


Python Scope.content方法代码示例

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


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

示例1: studio_view

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def studio_view(self, context):
        """
        Render a form for editing this XBlock
        """
        fragment = Fragment()
        context = {'fields': []}
        # Build a list of all the fields that can be edited:
        for field_name in self.editable_fields:
            field = self.fields[field_name]
            assert field.scope in (Scope.content, Scope.settings), (
                "Only Scope.content or Scope.settings fields can be used with "
                "StudioEditableXBlockMixin. Other scopes are for user-specific data and are "
                "not generally created/configured by content authors in Studio."
            )
            field_info = self._make_field_info(field_name, field)
            if field_info is not None:
                context["fields"].append(field_info)
        fragment.content = loader.render_django_template('templates/studio_edit.html', context)
        fragment.add_javascript(loader.load_unicode('public/studio_edit.js'))
        fragment.initialize_js('StudioEditableXBlockMixin')
        return fragment 
开发者ID:edx,项目名称:xblock-utils,代码行数:23,代码来源:studio_editable.py

示例2: author_preview_view

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def author_preview_view(self, context):
        """
        View for previewing contents in studio.
        """
        children_contents = []

        fragment = Fragment()
        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            child_fragment = self._render_child_fragment(child, context, 'preview_view')
            fragment.add_fragment_resources(child_fragment)
            children_contents.append(child_fragment.content)

        render_context = {
            'block': self,
            'children_contents': children_contents
        }
        render_context.update(context)
        fragment.add_content(self.loader.render_django_template(self.CHILD_PREVIEW_TEMPLATE, render_context))
        return fragment 
开发者ID:edx,项目名称:xblock-utils,代码行数:22,代码来源:studio_editable.py

示例3: fetch_available_3pm_transcripts

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def fetch_available_3pm_transcripts(self):
        """
        Fetch all available transcripts from 3PlayMedia API for current file ID.

        :return: (generator of OrderedDicts) all transcript's data
        """
        feedback, transcripts_list = self.get_3pm_transcripts_list(
            self.threeplaymedia_file_id, self.threeplaymedia_apikey
        )
        log.debug("Fetched 3PM transcripts list results:\n{}".format(feedback))

        if feedback['status'] is Status.error:
            log.error("3PlayMedia transcripts fetching API request has failed!\n{}".format(feedback['message']))
            raise StopIteration

        for transcript_data in transcripts_list:
            transcript = self.fetch_single_3pm_translation(transcript_data)
            if transcript is None:
                raise StopIteration
            transcript_ordered_dict = transcript._asdict()
            transcript_ordered_dict['content'] = ''  # we don't want to parse it to JSON
            yield transcript_ordered_dict 
开发者ID:appsembler,项目名称:xblock-video,代码行数:24,代码来源:mixins.py

示例4: fetch_from_three_play_media

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def fetch_from_three_play_media(self, request, _suffix=''):
        """
        Proxy handler to hide real API url.

        Arguments:
            request (webob.Request): The request to handle
            suffix (string): not used
            query string: 'language_id=transcript_id'
        Returns:
            webob.Response: WebVTT transcripts wrapped in Response object.
        """
        lang_id, transcript_id = request.query_string.split('=')
        transcript = self.fetch_single_3pm_translation(transcript_data={'id': transcript_id, 'language_id': lang_id})
        if transcript is None:
            return Response()
        return Response(transcript.content, content_type='text/vtt') 
开发者ID:appsembler,项目名称:xblock-video,代码行数:18,代码来源:mixins.py

示例5: __init__

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def __init__(self, authored_data, student_data):
        # Make sure that we don't repeatedly nest CmsFieldData instances
        if isinstance(authored_data, CmsFieldData):
            authored_data = authored_data._authored_data  # pylint: disable=protected-access

        self._authored_data = authored_data
        self._student_data = student_data

        super(CmsFieldData, self).__init__({
            Scope.content: authored_data,
            Scope.settings: authored_data,
            Scope.parent: authored_data,
            Scope.children: authored_data,
            Scope.user_state_summary: student_data,
            Scope.user_state: student_data,
            Scope.user_info: student_data,
            Scope.preferences: student_data,
        }) 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:20,代码来源:field_data.py

示例6: load_transcript

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def load_transcript(self, data, suffix=''):
        """
        Store user's cc language selection
        """
        threeplay_id = data.get('threeplay_id')
        transcript_id = data.get('transcript_id')
        content = ''

        if threeplay_id:
            content = Transcript.get_transcript_by_threeplay_id(
                api_key=self.get_attribute_or_default('api_key_3play'),
                threeplay_id=threeplay_id,
                transcript_id=transcript_id,
            )

        return {'content': content} 
开发者ID:edx-solutions,项目名称:xblock-ooyala,代码行数:18,代码来源:ooyala_player.py

示例7: render_children

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def render_children(self, context, fragment, can_reorder=True, can_add=False):
        """
        Renders the children of the module with HTML appropriate for Studio. If can_reorder is
        True, then the children will be rendered to support drag and drop.
        """
        contents = []

        child_context = {'reorderable_items': set()}
        if context:
            child_context.update(context)

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if can_reorder:
                child_context['reorderable_items'].add(child.scope_ids.usage_id)
            view_to_render = 'author_view' if hasattr(child, 'author_view') else 'student_view'
            rendered_child = child.render(view_to_render, child_context)
            fragment.add_fragment_resources(rendered_child)

            contents.append({
                'id': str(child.scope_ids.usage_id),
                'content': rendered_child.content
            })

        fragment.add_content(self.runtime.render_template("studio_render_children_view.html", {
            'items': contents,
            'xblock_context': context,
            'can_add': can_add,
            'can_reorder': can_reorder,
        })) 
开发者ID:edx,项目名称:xblock-utils,代码行数:32,代码来源:studio_editable.py

示例8: static_content

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def static_content(self):
        """
        Proxy to `xmodule.contentstore.StaticContent` class.
        """
        contentstore_service = self.runtime.service(self, 'contentstore')
        if contentstore_service:
            return contentstore_service.StaticContent

        return import_from('xmodule.contentstore.content', 'StaticContent') 
开发者ID:appsembler,项目名称:xblock-video,代码行数:11,代码来源:mixins.py

示例9: create_transcript_file

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def create_transcript_file(self, ext='.vtt', trans_str='', reference_name=''):
        """
        Upload a transcript, fetched from a video platform's API, to video xblock.

        Arguments:
            ext (str): format of transcript file, default is vtt.
            trans_str (str): multiple string for convert to vtt file.
            reference_name (str): name of transcript file.
        Returns:
            File's file_name and external_url.
        """
        # Define location of default transcript as a future asset and prepare content to store in assets
        file_name = reference_name.replace(" ", "_") + ext
        course_key = self.course_key
        content_loc = self.static_content.compute_location(course_key, file_name)  # AssetLocator object
        content = self.static_content(
            content_loc,
            file_name,
            'application/json',
            trans_str.encode('UTF-8')
        )  # StaticContent object
        external_url = '/' + str(content_loc)

        # Commit the content
        self.contentstore().save(content)

        return file_name, external_url 
开发者ID:appsembler,项目名称:xblock-video,代码行数:29,代码来源:mixins.py

示例10: fetch_single_3pm_translation

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def fetch_single_3pm_translation(self, transcript_data, format_id=TPMApiTranscriptFormatID.WEBVTT):
        """
        Fetch single transcript for given file ID in given format.

        :param transcript_data:
        :param format_id: defauts to VTT
        :return: (namedtuple instance) transcript data
        """
        transcript_id = transcript_data.get('id', '')
        lang_id = transcript_data.get('language_id')
        external_api_url = '{domain}files/{file_id}/transcripts/{tid}?apikey={api_key}&format_id={format_id}'.format(
            domain=self.THREE_PLAY_MEDIA_API_DOMAIN,
            file_id=self.threeplaymedia_file_id,
            tid=transcript_id,
            api_key=self.threeplaymedia_apikey,
            format_id=format_id
        )
        try:
            content = requests.get(external_api_url).text
        except Exception:  # pylint: disable=broad-except
            log.exception(_("Transcript fetching failure: language [{}]").format(TPMApiLanguage(lang_id)))
            return

        lang_code = TPMApiLanguage(lang_id)
        lang_label = lang_code.name
        video_id = self.get_player().media_id(self.href)
        source = TranscriptSource.THREE_PLAY_MEDIA
        return Transcript(
            id=transcript_id,
            content=content,
            lang=lang_code.iso_639_1_code,
            lang_id=lang_id,
            label=lang_label,
            video_id=video_id,
            format=format_id,
            source=source,
            url=external_api_url,
        ) 
开发者ID:appsembler,项目名称:xblock-video,代码行数:40,代码来源:mixins.py

示例11: _update_with_callback

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def _update_with_callback(xblock, user, old_metadata=None, old_content=None):
    """
    Updates the xblock in the modulestore.
    But before doing so, it calls the xblock's editor_saved callback function.
    """
    if callable(getattr(xblock, "editor_saved", None)):
        if old_metadata is None:
            old_metadata = own_metadata(xblock)
        if old_content is None:
            old_content = xblock.get_explicitly_set_fields_by_scope(Scope.content)
        xblock.editor_saved(user, old_metadata, old_content)

    # Update after the callback so any changes made in the callback will get persisted.
    return modulestore().update_item(xblock, user.id) 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:16,代码来源:item.py

示例12: _compute_visibility_state

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def _compute_visibility_state(xblock, child_info, is_unit_with_changes):
    """
    Returns the current publish state for the specified xblock and its children
    """
    if xblock.visible_to_staff_only:
        return VisibilityState.staff_only
    elif is_unit_with_changes:
        # Note that a unit that has never been published will fall into this category,
        # as well as previously published units with draft content.
        return VisibilityState.needs_attention
    is_unscheduled = xblock.start == DEFAULT_START_DATE
    is_live = datetime.now(UTC) > xblock.start
    children = child_info and child_info.get('children', [])
    if children and len(children) > 0:
        all_staff_only = True
        all_unscheduled = True
        all_live = True
        for child in child_info['children']:
            child_state = child['visibility_state']
            if child_state == VisibilityState.needs_attention:
                return child_state
            elif not child_state == VisibilityState.staff_only:
                all_staff_only = False
                if not child_state == VisibilityState.unscheduled:
                    all_unscheduled = False
                    if not child_state == VisibilityState.live:
                        all_live = False
        if all_staff_only:
            return VisibilityState.staff_only
        elif all_unscheduled:
            return VisibilityState.unscheduled if is_unscheduled else VisibilityState.needs_attention
        elif all_live:
            return VisibilityState.live if is_live else VisibilityState.needs_attention
        else:
            return VisibilityState.ready if not is_unscheduled else VisibilityState.needs_attention
    if is_unscheduled:
        return VisibilityState.unscheduled
    elif is_live:
        return VisibilityState.live
    else:
        return VisibilityState.ready 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:43,代码来源:item.py

示例13: load_resource

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def load_resource(self, resource_path):
        """
        Gets the content of a resource
        """
        resource_content = pkg_resources.resource_string(__name__, resource_path)
        return unicode(resource_content) 
开发者ID:MarCnu,项目名称:videojsXBlock,代码行数:8,代码来源:videojs.py

示例14: _duplicate_item

# 需要导入模块: from xblock.fields import Scope [as 别名]
# 或者: from xblock.fields.Scope import content [as 别名]
def _duplicate_item(parent_usage_key, duplicate_source_usage_key, user, display_name=None):
    """
    Duplicate an existing xblock as a child of the supplied parent_usage_key.
    """
    store = modulestore()
    with store.bulk_operations(duplicate_source_usage_key.course_key):
        source_item = store.get_item(duplicate_source_usage_key)
        # Change the blockID to be unique.
        dest_usage_key = source_item.location.replace(name=uuid4().hex)
        category = dest_usage_key.block_type

        # Update the display name to indicate this is a duplicate (unless display name provided).
        duplicate_metadata = own_metadata(source_item)
        if display_name is not None:
            duplicate_metadata['display_name'] = display_name
        else:
            if source_item.display_name is None:
                duplicate_metadata['display_name'] = _("Duplicate of {0}").format(source_item.category)
            else:
                duplicate_metadata['display_name'] = _("Duplicate of '{0}'").format(source_item.display_name)

        dest_module = store.create_item(
            user.id,
            dest_usage_key.course_key,
            dest_usage_key.block_type,
            block_id=dest_usage_key.block_id,
            definition_data=source_item.get_explicitly_set_fields_by_scope(Scope.content),
            metadata=duplicate_metadata,
            runtime=source_item.runtime,
        )

        # Children are not automatically copied over (and not all xblocks have a 'children' attribute).
        # Because DAGs are not fully supported, we need to actually duplicate each child as well.
        if source_item.has_children:
            dest_module.children = []
            for child in source_item.children:
                dupe = _duplicate_item(dest_module.location, child, user=user)
                dest_module.children.append(dupe)
            store.update_item(dest_module, user.id)

        if 'detached' not in source_item.runtime.load_block_type(category)._class_tags:
            parent = store.get_item(parent_usage_key)
            # If source was already a child of the parent, add duplicate immediately afterward.
            # Otherwise, add child to end.
            if source_item.location in parent.children:
                source_index = parent.children.index(source_item.location)
                parent.children.insert(source_index + 1, dest_module.location)
            else:
                parent.children.append(dest_module.location)
            store.update_item(parent, user.id)

        return dest_module.location 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:54,代码来源:item.py


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