本文整理汇总了Python中web_fragments.fragment.Fragment类的典型用法代码示例。如果您正苦于以下问题:Python Fragment类的具体用法?Python Fragment怎么用?Python Fragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fragment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: student_view
def student_view(self, context):
""" Renders parameters to template. """
context = {
'course_key': self.runtime.course_id,
'display_name': self.display_name_with_default_escaped,
'tag': self.instructor_tags,
'source': self.source,
'instructions_html': self.instructions,
'content_html': self.content,
'token': retrieve_token(self.user_email, self.annotation_token_secret),
'diacritic_marks': self.diacritics,
'annotation_storage': self.annotation_storage_url,
'default_tab': self.default_tab,
'instructor_email': self.instructor_email,
'annotation_mode': self.annotation_mode,
'is_course_staff': self.is_course_staff,
}
fragment = Fragment(self.system.render_template('textannotation.html', context))
# TinyMCE already exists in Studio so we should not load the files again
# get_real_user always returns "None" in Studio since its runtimes contains no anonymous ids
if self.runtime.get_real_user is not None:
fragment.add_javascript_url(self.runtime.STATIC_URL + "js/vendor/tinymce/js/tinymce/tinymce.full.min.js")
fragment.add_javascript_url(self.runtime.STATIC_URL + "js/vendor/tinymce/js/tinymce/jquery.tinymce.min.js")
return fragment
开发者ID:luisvasq,项目名称:edx-platform,代码行数:25,代码来源:textannotation_module.py
示例2: student_view_aside
def student_view_aside(self, block, context): # pylint: disable=unused-argument
"""
Display the tag selector with specific categories and allowed values,
depending on the context.
"""
if isinstance(block, CapaModule):
tags = []
for tag in self.get_available_tags():
tag_available_values = tag.get_values()
tag_current_values = self.saved_tags.get(tag.name, [])
if isinstance(tag_current_values, basestring):
tag_current_values = [tag_current_values]
tag_values_not_exists = [cur_val for cur_val in tag_current_values
if cur_val not in tag_available_values]
tag_values_available_to_choose = tag_available_values + tag_values_not_exists
tag_values_available_to_choose.sort()
tags.append({
'key': tag.name,
'title': tag.title,
'values': tag_values_available_to_choose,
'current_values': tag_current_values,
})
fragment = Fragment(render_to_string('structured_tags_block.html', {'tags': tags,
'tags_count': len(tags),
'block_location': block.location}))
fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock_asides/structured_tags.js'))
fragment.initialize_js('StructuredTagsInit')
return fragment
else:
return Fragment(u'')
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:34,代码来源:tagging.py
示例3: _student_view
def _student_view(self, context, prereq_met, prereq_meta_info, banner_text=None):
"""
Returns the rendered student view of the content of this
sequential. If banner_text is given, it is added to the
content.
"""
display_items = self.get_display_items()
self._update_position(context, len(display_items))
if prereq_met and not self._is_gate_fulfilled():
banner_text = _('This section is a prerequisite. You must complete this section in order to unlock additional content.')
fragment = Fragment()
params = {
'items': self._render_student_view_for_items(context, display_items, fragment) if prereq_met else [],
'element_id': self.location.html_id(),
'item_id': text_type(self.location),
'position': self.position,
'tag': self.location.block_type,
'ajax_url': self.system.ajax_url,
'next_url': context.get('next_url'),
'prev_url': context.get('prev_url'),
'banner_text': banner_text,
'save_position': self.is_user_authenticated(context),
'show_completion': self.is_user_authenticated(context),
'gated_content': self._get_gated_content_info(prereq_met, prereq_meta_info)
}
fragment.add_content(self.system.render_template("seq_module.html", params))
self._capture_full_seq_item_metrics(display_items)
self._capture_current_unit_metrics(display_items)
return fragment
开发者ID:mitocw,项目名称:edx-platform,代码行数:33,代码来源:seq_module.py
示例4: create_fragment
def create_fragment(self, content=None):
"""
Create a fragment.
"""
fragment = Fragment(content)
fragment.add_css('body {background-color:red;}')
fragment.add_javascript('alert("Hi!");')
return fragment
开发者ID:mitodl,项目名称:edx-platform,代码行数:8,代码来源:test_xblock_utils.py
示例5: wrap_fragment
def wrap_fragment(fragment, new_content):
"""
Returns a new Fragment that has `new_content` and all
as its content, and all of the resources from fragment
"""
wrapper_frag = Fragment(content=new_content)
wrapper_frag.add_fragment_resources(fragment)
return wrapper_frag
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:8,代码来源:__init__.py
示例6: author_view
def author_view(self, context=None): # pylint: disable=unused-argument
"""
Renders author view for Studio.
"""
fragment = Fragment()
fragment.add_content(self.runtime.render_template(
'discussion/_discussion_inline_studio.html',
{'discussion_id': self.discussion_id}
))
return fragment
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:10,代码来源:xblock_discussion.py
示例7: student_view
def student_view(self, context):
"""
Renders the student view of the block in the LMS.
"""
fragment = Fragment()
contents = []
if context:
child_context = copy(context)
else:
child_context = {}
if 'bookmarked' not in child_context:
bookmarks_service = self.runtime.service(self, 'bookmarks')
child_context['bookmarked'] = bookmarks_service.is_bookmarked(usage_key=self.location), # pylint: disable=no-member
if 'username' not in child_context:
user_service = self.runtime.service(self, 'user')
child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']
child_blocks = self.get_display_items()
child_blocks_to_complete_on_view = set()
completion_service = self.runtime.service(self, 'completion')
if completion_service and completion_service.completion_tracking_enabled():
child_blocks_to_complete_on_view = completion_service.blocks_to_mark_complete_on_view(child_blocks)
complete_on_view_delay = completion_service.get_complete_on_view_delay_ms()
child_context['child_of_vertical'] = True
is_child_of_vertical = context.get('child_of_vertical', False)
# pylint: disable=no-member
for child in child_blocks:
child_block_context = copy(child_context)
if child in child_blocks_to_complete_on_view:
child_block_context['wrap_xblock_data'] = {
'mark-completed-on-view-after-delay': complete_on_view_delay
}
rendered_child = child.render(STUDENT_VIEW, child_block_context)
fragment.add_fragment_resources(rendered_child)
contents.append({
'id': six.text_type(child.location),
'content': rendered_child.content
})
fragment.add_content(self.system.render_template('vert_module.html', {
'items': contents,
'xblock_context': context,
'unit_title': self.display_name_with_default if not is_child_of_vertical else None,
'show_bookmark_button': child_context.get('show_bookmark_button', not is_child_of_vertical),
'bookmarked': child_context['bookmarked'],
'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)), # pylint: disable=no-member
}))
for tag in webpack_loader.utils.get_as_tags('VerticalStudentView'):
fragment.add_resource(tag, mimetype='text/html', placement='head')
fragment.initialize_js('VerticalStudentView')
return fragment
开发者ID:cmscom,项目名称:edx-platform,代码行数:59,代码来源:vertical_block.py
示例8: render_to_fragment
def render_to_fragment(self, request, course_id=None, discussion_id=None, thread_id=None, **kwargs):
"""
Render the discussion board to a fragment.
Args:
request: The Django request.
course_id: The id of the course in question.
discussion_id: An optional discussion ID to be focused upon.
thread_id: An optional ID of the thread to be shown.
Returns:
Fragment: The fragment representing the discussion board
"""
course_key = CourseKey.from_string(course_id)
try:
base_context = _create_base_discussion_view_context(request, course_key)
# Note:
# After the thread is rendered in this fragment, an AJAX
# request is made and the thread is completely loaded again
# (yes, this is something to fix). Because of this, we pass in
# raise_event=False to _load_thread_for_viewing avoid duplicate
# tracking events.
thread = (
_load_thread_for_viewing(
request,
base_context['course'],
discussion_id=discussion_id,
thread_id=thread_id,
raise_event=False,
)
if thread_id
else None
)
context = _create_discussion_board_context(request, base_context, thread=thread)
html = render_to_string('discussion/discussion_board_fragment.html', context)
inline_js = render_to_string('discussion/discussion_board_js.template', context)
fragment = Fragment(html)
self.add_fragment_resource_urls(fragment)
fragment.add_javascript(inline_js)
if not settings.REQUIRE_DEBUG:
fragment.add_javascript_url(staticfiles_storage.url('discussion/js/discussion_board_factory.js'))
return fragment
except cc.utils.CommentClientMaintenanceError:
log.warning('Forum is in maintenance mode')
html = render_to_response('discussion/maintenance_fragment.html', {
'disable_courseware_js': True,
'uses_pattern_library': True,
})
return Fragment(html)
开发者ID:svejk,项目名称:edx-platform,代码行数:50,代码来源:views.py
示例9: student_view
def student_view(self, context):
"""
Renders the output that a student will see.
"""
fragment = Fragment()
fragment.add_content(self.system.render_template('word_cloud.html', {
'ajax_url': self.system.ajax_url,
'display_name': self.display_name,
'instructions': self.instructions,
'element_class': self.location.block_type,
'element_id': self.location.html_id(),
'num_inputs': self.num_inputs,
'submitted': self.submitted,
}))
return fragment
开发者ID:cmscom,项目名称:edx-platform,代码行数:17,代码来源:word_cloud_module.py
示例10: author_view
def author_view(self, context):
"""
Renders the Studio views.
Normal studio view: If block is properly configured, displays library status summary
Studio container view: displays a preview of all possible children.
"""
fragment = Fragment()
root_xblock = context.get('root_xblock')
is_root = root_xblock and root_xblock.location == self.location
if is_root:
# User has clicked the "View" link. Show a preview of all possible children:
if self.children: # pylint: disable=no-member
fragment.add_content(self.system.render_template("library-block-author-preview-header.html", {
'max_count': self.max_count,
'display_name': self.display_name or self.url_name,
}))
context['can_edit_visibility'] = False
context['can_move'] = False
self.render_children(context, fragment, can_reorder=False, can_add=False)
# else: When shown on a unit page, don't show any sort of preview -
# just the status of this block in the validation area.
# The following JS is used to make the "Update now" button work on the unit page and the container view:
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/library_content_edit.js'))
fragment.initialize_js('LibraryContentAuthorView')
return fragment
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:27,代码来源:library_content_module.py
示例11: author_view
def author_view(self, context):
"""
Renders the Studio preview by rendering each child so that they can all be seen and edited.
"""
fragment = Fragment()
root_xblock = context.get('root_xblock')
is_root = root_xblock and root_xblock.location == self.location
active_groups_preview = None
inactive_groups_preview = None
if is_root:
[active_children, inactive_children] = self.descriptor.active_and_inactive_children()
active_groups_preview = self.studio_render_children(
fragment, active_children, context
)
inactive_groups_preview = self.studio_render_children(
fragment, inactive_children, context
)
fragment.add_content(self.system.render_template('split_test_author_view.html', {
'split_test': self,
'is_root': is_root,
'is_configured': self.is_configured,
'active_groups_preview': active_groups_preview,
'inactive_groups_preview': inactive_groups_preview,
'group_configuration_url': self.descriptor.group_configuration_url,
}))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_author_view.js'))
fragment.initialize_js('SplitTestAuthorView')
return fragment
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:31,代码来源:split_test_module.py
示例12: student_view
def student_view(self, context=None):
"""
Renders student view for LMS.
"""
fragment = Fragment()
self.add_resource_urls(fragment)
login_msg = ''
if not self.django_user.is_authenticated():
qs = urllib.urlencode({
'course_id': self.course_key,
'enrollment_action': 'enroll',
'email_opt_in': False,
})
login_msg = Text(_("You are not signed in. To view the discussion content, {sign_in_link} or "
"{register_link}, and enroll in this course.")).format(
sign_in_link=HTML('<a href="{url}">{sign_in_label}</a>').format(
sign_in_label=_('sign in'),
url='{}?{}'.format(reverse('signin_user'), qs),
),
register_link=HTML('<a href="/{url}">{register_label}</a>').format(
register_label=_('register'),
url='{}?{}'.format(reverse('register_user'), qs),
),
)
context = {
'discussion_id': self.discussion_id,
'display_name': self.display_name if self.display_name else _("Discussion"),
'user': self.django_user,
'course_id': self.course_key,
'discussion_category': self.discussion_category,
'discussion_target': self.discussion_target,
'can_create_thread': self.has_permission("create_thread"),
'can_create_comment': self.has_permission("create_comment"),
'can_create_subcomment': self.has_permission("create_sub_comment"),
'login_msg': login_msg,
}
fragment.add_content(self.runtime.render_template('discussion/_discussion_inline.html', context))
fragment.initialize_js('DiscussionInlineBlock')
return fragment
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:45,代码来源:xblock_discussion.py
示例13: student_view
def student_view(self, context):
"""
Renders the student view of the block in the LMS.
"""
fragment = Fragment()
contents = []
if context:
child_context = copy(context)
else:
child_context = {}
if 'bookmarked' not in child_context:
bookmarks_service = self.runtime.service(self, 'bookmarks')
child_context['bookmarked'] = bookmarks_service.is_bookmarked(usage_key=self.location), # pylint: disable=no-member
if 'username' not in child_context:
user_service = self.runtime.service(self, 'user')
child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']
completion_service = self.runtime.service(self, 'completion')
child_context['child_of_vertical'] = True
is_child_of_vertical = context.get('child_of_vertical', False)
# pylint: disable=no-member
for child in self.get_display_items():
rendered_child = child.render(STUDENT_VIEW, child_context)
fragment.add_fragment_resources(rendered_child)
contents.append({
'id': six.text_type(child.location),
'content': rendered_child.content
})
fragment.add_content(self.system.render_template('vert_module.html', {
'items': contents,
'xblock_context': context,
'unit_title': self.display_name_with_default if not is_child_of_vertical else None,
'show_bookmark_button': child_context.get('show_bookmark_button', not is_child_of_vertical),
'bookmarked': child_context['bookmarked'],
'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)), # pylint: disable=no-member
'watched_completable_blocks': self.get_completable_by_viewing(completion_service),
'completion_delay_ms': self.get_completion_delay_ms(completion_service),
}))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vertical_student_view.js'))
fragment.initialize_js('VerticalStudentView')
return fragment
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:49,代码来源:vertical_block.py
示例14: render_to_fragment
def render_to_fragment(self, request, course_id=None, **kwargs):
"""
Renders the user's course bookmarks as a fragment.
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
context = {
'csrf': csrf(request)['csrf_token'],
'course': course,
'bookmarks_api_url': reverse('bookmarks'),
'language_preference': 'en', # TODO:
}
html = render_to_string('course_bookmarks/course-bookmarks-fragment.html', context)
inline_js = render_to_string('course_bookmarks/course_bookmarks_js.template', context)
fragment = Fragment(html)
self.add_fragment_resource_urls(fragment)
fragment.add_javascript(inline_js)
return fragment
开发者ID:edx-solutions,项目名称:edx-platform,代码行数:19,代码来源:course_bookmarks.py
示例15: _wrap_ele
def _wrap_ele(self, block, view, frag, extra_data=None):
"""
Does the guts of the wrapping the same way for both xblocks and asides. Their
wrappers provide other info in extra_data which gets put into the dom data- attrs.
"""
wrapped = Fragment()
data = {
'usage': block.scope_ids.usage_id,
'block-type': block.scope_ids.block_type,
}
data.update(extra_data)
if frag.js_init_fn:
data['init'] = frag.js_init_fn
data['runtime-version'] = frag.js_init_version
json_init = ""
# TODO/Note: We eventually want to remove: hasattr(frag, 'json_init_args')
# However, I'd like to maintain backwards-compatibility with older XBlock
# for at least a little while so as not to adversely effect developers.
# pmitros/Jun 28, 2014.
if hasattr(frag, 'json_init_args') and frag.json_init_args is not None:
json_init = (
'<script type="json/xblock-args" class="xblock_json_init_args">'
'{data}</script>'
).format(data=json.dumps(frag.json_init_args))
block_css_entrypoint = block.entry_point.replace('.', '-')
css_classes = [
block_css_entrypoint,
'{}-{}'.format(block_css_entrypoint, view),
]
html = "<div class='{}'{properties}>{body}{js}</div>".format(
markupsafe.escape(' '.join(css_classes)),
properties="".join(" data-%s='%s'" % item for item in list(data.items())),
body=frag.body_html(),
js=json_init)
wrapped.add_content(html)
wrapped.add_fragment_resources(frag)
return wrapped
开发者ID:edx,项目名称:XBlock,代码行数:42,代码来源:runtime.py
示例16: student_view
def student_view(self, context):
fragment = Fragment()
contents = []
child_context = {} if not context else copy(context)
for child in self._get_selected_child_blocks():
for displayable in child.displayable_items():
rendered_child = displayable.render(STUDENT_VIEW, child_context)
fragment.add_fragment_resources(rendered_child)
contents.append({
'id': text_type(displayable.location),
'content': rendered_child.content,
})
fragment.add_content(self.system.render_template('vert_module.html', {
'items': contents,
'xblock_context': context,
'show_bookmark_button': False,
'watched_completable_blocks': set(),
}))
return fragment
开发者ID:TeachAtTUM,项目名称:edx-platform,代码行数:21,代码来源:library_content_module.py
示例17: _student_view
def _student_view(self, context, banner_text=None):
"""
Returns the rendered student view of the content of this
sequential. If banner_text is given, it is added to the
content.
"""
display_items = self.get_display_items()
self._update_position(context, len(display_items))
prereq_met = True
prereq_meta_info = {}
if self._required_prereq():
if self.runtime.user_is_staff:
banner_text = _('This subsection is unlocked for learners when they meet the prerequisite requirements.')
else:
# check if prerequisite has been met
prereq_met, prereq_meta_info = self._compute_is_prereq_met(True)
if prereq_met and not self._is_gate_fulfilled():
banner_text = _('This section is a prerequisite. You must complete this section in order to unlock additional content.')
fragment = Fragment()
params = {
'items': self._render_student_view_for_items(context, display_items, fragment) if prereq_met else [],
'element_id': self.location.html_id(),
'item_id': text_type(self.location),
'position': self.position,
'tag': self.location.block_type,
'ajax_url': self.system.ajax_url,
'next_url': context.get('next_url'),
'prev_url': context.get('prev_url'),
'banner_text': banner_text,
'disable_navigation': not self.is_user_authenticated(context),
'gated_content': self._get_gated_content_info(prereq_met, prereq_meta_info)
}
fragment.add_content(self.system.render_template("seq_module.html", params))
self._capture_full_seq_item_metrics(display_items)
self._capture_current_unit_metrics(display_items)
return fragment
开发者ID:luisvasq,项目名称:edx-platform,代码行数:40,代码来源:seq_module.py
示例18: render_to_fragment
def render_to_fragment(self, request, course_id=None, discussion_id=None, thread_id=None, **kwargs):
"""
Render the discussion board to a fragment.
Args:
request: The Django request.
course_id: The id of the course in question.
discussion_id: An optional discussion ID to be focused upon.
thread_id: An optional ID of the thread to be shown.
Returns:
Fragment: The fragment representing the discussion board
"""
course_key = CourseKey.from_string(course_id)
try:
context = _create_discussion_board_context(
request,
course_key,
discussion_id=discussion_id,
thread_id=thread_id,
)
html = render_to_string('discussion/discussion_board_fragment.html', context)
inline_js = render_to_string('discussion/discussion_board_js.template', context)
fragment = Fragment(html)
self.add_fragment_resource_urls(fragment)
fragment.add_javascript(inline_js)
if not settings.REQUIRE_DEBUG:
fragment.add_javascript_url(staticfiles_storage.url('discussion/js/discussion_board_factory.js'))
return fragment
except cc.utils.CommentClientMaintenanceError:
log.warning('Forum is in maintenance mode')
html = render_to_response('discussion/maintenance_fragment.html', {
'disable_courseware_js': True,
'uses_pattern_library': True,
})
return Fragment(html)
开发者ID:stvstnfrd,项目名称:edx-platform,代码行数:37,代码来源:views.py
示例19: layout_asides
def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
position_for_asides = '<!-- footer for xblock_aside -->'
result = Fragment()
result.add_fragment_resources(frag)
for aside, aside_fn in aside_frag_fns:
aside_frag = aside_fn(block, context)
if aside_frag.content != u'':
aside_frag_wrapped = self.wrap_aside(block, aside, view_name, aside_frag, context)
aside.save()
result.add_fragment_resources(aside_frag_wrapped)
replacement = position_for_asides + aside_frag_wrapped.content
frag.content = frag.content.replace(position_for_asides, replacement)
result.add_content(frag.content)
return result
开发者ID:cpennington,项目名称:edx-platform,代码行数:16,代码来源:preview.py
示例20: visibility_view
def visibility_view(self, _context=None):
"""
Render the view to manage an xblock's visibility settings in Studio.
Args:
_context: Not actively used for this view.
Returns:
(Fragment): An HTML fragment for editing the visibility of this XBlock.
"""
fragment = Fragment()
from contentstore.utils import reverse_course_url
fragment.add_content(self.system.render_template('visibility_editor.html', {
'xblock': self,
'manage_groups_url': reverse_course_url('group_configurations_list_handler', self.location.course_key),
}))
fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock/authoring.js'))
fragment.initialize_js('VisibilityEditorInit')
return fragment
开发者ID:AlexxNica,项目名称:edx-platform,代码行数:17,代码来源:authoring_mixin.py
注:本文中的web_fragments.fragment.Fragment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论