本文整理汇总了Python中xblock.fragment.Fragment方法的典型用法代码示例。如果您正苦于以下问题:Python fragment.Fragment方法的具体用法?Python fragment.Fragment怎么用?Python fragment.Fragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xblock.fragment
的用法示例。
在下文中一共展示了fragment.Fragment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, context): # pylint: disable=unused-argument
"""
Player view, displayed to the student
"""
fragment = Fragment()
fragment.add_content(RESOURCE_LOADER.render_django_template(
DOCUMENT_TEMPLATE,
context={"self": self},
i18n_service=self.runtime.service(self, 'i18n'),
))
fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_docs.css'))
fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_docs.js'))
fragment.initialize_js('GoogleDocumentBlock')
return fragment
# Context argument is specified for xblocks, but we are not using herein
示例2: studio_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def studio_view(self, context): # pylint: disable=unused-argument
"""
Editing view in Studio
"""
fragment = Fragment()
# Need to access protected members of fields to get their default value
default_name = self.fields['display_name']._default # pylint: disable=protected-access,unsubscriptable-object
fragment.add_content(RESOURCE_LOADER.render_template(DOCUMENT_EDIT_TEMPLATE, {
'self': self,
'defaultName': default_name,
}))
fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_docs_edit.js'))
fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css'))
fragment.initialize_js('GoogleDocumentEditBlock')
return fragment
# suffix argument is specified for xblocks, but we are not using herein
示例3: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, context): # pylint: disable=unused-argument
"""
Player view, displayed to the student
"""
fragment = Fragment()
fragment.add_content(RESOURCE_LOADER.render_django_template(
CALENDAR_TEMPLATE,
context={
"mode": self.views[self.default_view][1],
"src": self.calendar_id,
"title": self.display_name,
"language": utils.translation.get_language(),
},
i18n_service=self.runtime.service(self, "i18n"),
))
fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_calendar.css'))
fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar.js'))
fragment.initialize_js('GoogleCalendarBlock')
return fragment
# Context argument is specified for xblocks, but we are not using herein
示例4: studio_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def studio_view(self, context): # pylint: disable=unused-argument
"""
Editing view in Studio
"""
fragment = Fragment()
# Need to access protected members of fields to get their default value
default_name = self.fields['display_name']._default # pylint: disable=protected-access,unsubscriptable-object
fragment.add_content(RESOURCE_LOADER.render_template(CALENDAR_EDIT_TEMPLATE, {
'self': self,
'defaultName': default_name,
'defaultID': self.fields['calendar_id']._default # pylint: disable=protected-access,unsubscriptable-object
}))
fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar_edit.js'))
fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css'))
fragment.initialize_js('GoogleCalendarEditBlock')
return fragment
# suffix argument is specified for xblocks, but we are not using herein
示例5: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, context):
"""Provide the default student view."""
# WARNING: This assumes that the XBlock container does not refresh
# or redirect pages so that the location hash disappears. It also
# assumes that there are no other hashes.
user_id = self._get_current_user_id()
room_id = self.user_id_to_room_id.get(user_id, '')
frag = Fragment(self._jinja_env.get_template(
self.STUDENT_TEMPLATE_PATH).render({'room_id': room_id}))
frag.add_css(self._get_resource_string(
'public/lib/candy/res/default.css'))
frag.add_css(self._get_resource_string('public/css/chat.css'))
frag.add_javascript(self._get_resource_string(self.STUDENT_JS_PATH))
js_dep_paths = [
'public/lib/candy/libs/libs.min.js',
'public/lib/candy/candy.bundle.js',
]
for js_dep_path in js_dep_paths:
frag.add_javascript(self._get_resource_string(js_dep_path))
frag.initialize_js('Chat')
return frag
示例6: studio_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def studio_view(self, context=None):
"""
The secondary view of the XBlock, shown to teachers
when editing the XBlock.
"""
context = {
'display_name': self.display_name,
'url': self.url,
'allow_download': self.allow_download,
'source_text': self.source_text,
'source_url': self.source_url,
'start_time': self.start_time,
'end_time': self.end_time
}
html = self.render_template('static/html/videojs_edit.html', context)
frag = Fragment(html)
frag.add_javascript(self.load_resource("static/js/videojs_edit.js"))
frag.initialize_js('videojsXBlockInitStudio')
return frag
示例7: studio_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def studio_view(self, context=None):
"""
The secondary view of the XBlock, shown to teachers
when editing the XBlock.
"""
context = {
'display_name': self.display_name,
'app_id' : self.app_id,
'file_id': self.file_id,
'width': self.width,
'height': self.height
}
html = self.render_template('static/html/youku_edit.html', context)
frag = Fragment(html)
frag.add_javascript(self.load_resource("static/js/youku_edit.js"))
frag.initialize_js('youkuXBlockInitStudio')
return frag
示例8: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, context=None):
base = reverse('xblock_jupyter_viewer:jupyter_nb_viewer') + "?{}"
# setup start/end tags
if self.start_tag != '':
base += "&{}".format(urlencode({'start': self.start_tag}))
if self.end_tag != '':
base += "&{}".format(urlencode({'end': self.end_tag}))
# Add Image root
base += "&{}".format(urlencode({'images_url': self.image_url}))
# setup full url and inject into template iframe
full_url = base.format(urlencode({'url': self.jupyter_url}))
log.debug("Full URL: {}".format(full_url))
base_html = self.resource_string('static/html/student_view.html')\
.format(self.xblock_height, full_url)
# add html and css
frag = Fragment(base_html)
# frag.add_css(self.resource_string('static/css/style.css'))
return frag
# TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock.
示例9: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, context=None):
context_html = self.get_context_student()
template = self.render_template('static/html/scormxblock.html', context_html)
frag = Fragment(template)
frag.add_css(self.resource_string("static/css/scormxblock.css"))
frag.add_javascript(self.resource_string("static/js/src/scormxblock.js"))
settings = {
'version_scorm': self.version_scorm
}
frag.initialize_js('ScormXBlock', json_args=settings)
return frag
示例10: studio_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def studio_view(self, context=None):
context_html = self.get_context_studio()
template = self.render_template('static/html/studio.html', context_html)
frag = Fragment(template)
frag.add_css(self.resource_string("static/css/scormxblock.css"))
frag.add_javascript(self.resource_string("static/js/src/studio.js"))
frag.initialize_js('ScormStudioXBlock')
return frag
示例11: author_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def author_view(self, context=None):
html = self.render_template("static/html/author_view.html", context)
frag = Fragment(html)
return frag
示例12: get_frag
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def get_frag(self, **context): # pylint: disable=unused-argument
"""
Return a Fragment required to render video player on the client side.
"""
return Fragment(u'[Here be Video]')
示例13: get_frag
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def get_frag(self, **context):
"""
Compose an XBlock fragment with video player to be rendered in student view.
Brightcove backend is a special case and doesn't use vanilla Video.js player.
Because of this it doesn't use `super.get_frag()`.
"""
context['player_state'] = json.dumps(context['player_state'])
log.debug('CONTEXT: player_state: %s', context.get('player_state'))
frag = Fragment(
self.render_template('brightcove.html', **context)
)
frag.add_css_url(
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'
)
frag.add_javascript(
self.render_resource('static/js/context.js', **context)
)
js_files = [
'static/js/base.js',
'static/vendor/js/array-from-polyfill.js',
'static/js/student-view/player-state.js'
]
js_files += [
'static/js/videojs/videojs-tabindex.js',
'static/js/videojs/toggle-button.js',
'static/js/videojs/videojs-event-plugin.js',
'static/js/videojs/brightcove-videojs-init.js',
]
for js_file in js_files:
frag.add_javascript(self.resource_string(js_file))
frag.add_css(
self.resource_string('static/css/brightcove.css')
)
log.debug("[get_frag] initialized scripts: %s", js_files)
return frag
示例14: student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def student_view(self, _context=None):
"""
The primary view of the `VideoXBlock`, shown to students when viewing courses.
"""
player_url = self.runtime.handler_url(self, 'render_player')
download_transcript_handler_url = self.runtime.handler_url(self, 'download_transcript')
transcript_download_link = self.get_transcript_download_link()
full_transcript_download_link = ''
if transcript_download_link:
full_transcript_download_link = download_transcript_handler_url + transcript_download_link
context = {
'player_url': player_url,
'display_name': self.display_name,
'usage_id': self.usage_id,
'handout': self.handout,
'transcripts': list(self.route_transcripts()),
'download_transcript_allowed': self.download_transcript_allowed,
'transcripts_streaming_enabled': self.threeplaymedia_streaming,
'download_video_url': self.get_download_video_url(),
'handout_file_name': self.get_file_name_from_path(self.handout),
'transcript_download_link': full_transcript_download_link,
'version': __version__
}
log.debug("[student_view_context]: transcripts %s", context['transcripts'])
frag = Fragment(
render_resource(
'static/html/student_view.html',
**context
)
)
frag.add_javascript(resource_string("static/js/student-view/video-xblock.js"))
frag.add_css(resource_string("static/css/student-view.css"))
frag.initialize_js('VideoXBlockStudentViewInit')
return frag
示例15: test_student_view
# 需要导入模块: from xblock import fragment [as 别名]
# 或者: from xblock.fragment import Fragment [as 别名]
def test_student_view(self, route_transcripts, resource_string_mock, render_resource_mock):
"""
Test xBlock's student view builds proper Fragment.
"""
# Arrange
unused_context_stub = object()
render_resource_mock.return_value = u'<iframe/>'
handler_url = self.xblock.runtime.handler_url = Mock()
handler_url.side_effect = ['/player/url', '/transcript/download/url']
route_transcripts.return_value = ['transcripts.vtt']
self.xblock.get_transcript_download_link = Mock(return_value='/transcript/link.vtt')
self.xblock.threeplaymedia_streaming = True
# Act
student_view = self.xblock.student_view(unused_context_stub)
# Assert
self.assertIsInstance(student_view, Fragment)
render_resource_mock.assert_called_once_with(
'static/html/student_view.html',
display_name='Video',
download_transcript_allowed=False,
transcripts_streaming_enabled=True,
download_video_url=False,
handout='',
handout_file_name='',
player_url='/player/url',
transcript_download_link='/transcript/download/url'+'/transcript/link.vtt',
transcripts=['transcripts.vtt'],
usage_id='usage_id',
version=__version__,
)
resource_string_mock.assert_called_with('static/css/student-view.css')
handler_url.assert_called_with(self.xblock, 'download_transcript')
route_transcripts.assert_called_once_with()