本文整理汇总了Python中xblock.fragment.Fragment类的典型用法代码示例。如果您正苦于以下问题:Python Fragment类的具体用法?Python Fragment怎么用?Python Fragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fragment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: author_view
def author_view(self, context):
"""
Renders the Studio preview view, which supports drag and drop.
"""
fragment = Fragment()
contents = []
for child_key in self.children: # pylint: disable=E1101
context['reorderable_items'].add(child_key)
child = self.runtime.get_block(child_key)
rendered_child = self.runtime.render_child(child, StudioEditableModule.get_preview_view_name(child), context)
fragment.add_frag_resources(rendered_child)
contents.append({
'id': unicode(child_key),
'content': rendered_child.content,
})
fragment.add_content(self.runtime.render_template("studio_render_children_view.html", {
'items': contents,
'xblock_context': context,
'can_add': True,
'can_reorder': True,
}))
return fragment
示例2: student_view
def student_view(self, context=None):
"""
The primary view of the ContentXBlock, shown to students
when viewing courses.
"""
if self.contnet_type == "content":
result = Fragment()
url = "public/html/"+self.short_name+".html"
fragment = Fragment(self.resource_string(url))
html_template = Template(self.resource_string("templates/student_view.html"))
html_context = Context({"fragment": fragment})
html_str = html_template.render(html_context)
result.add_content(html_str)
return result
elif self.contnet_type == "topnav":
html_context = Context({"source_link": self.source_link,
"prev_link": self.prev_link,
"prev_name": self.prev_name,
"toc_link": self.toc_link,
"next_link": self.next_link,
"next_name": self.next_name,
})
html_template = Template(self.resource_string("templates/student_view_topnav.html"))
fragment = Fragment(html_template.render(html_context))
return fragment
elif self.contnet_type == "header":
return
elif self.contnet_type == "footer":
return
示例3: _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))
fragment = Fragment()
params = {
'items': self._render_student_view_for_items(context, display_items, fragment),
'element_id': self.location.html_id(),
'item_id': self.location.to_deprecated_string(),
'position': self.position,
'tag': self.location.category,
'ajax_url': self.system.ajax_url,
'next_url': context.get('next_url'),
'prev_url': context.get('prev_url'),
'banner_text': banner_text,
}
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
示例4: studio_view
def studio_view(self, context=None):
"""This is the view displaying xblock form in studio."""
logger.debug("On entre dans la partie prof")
# logger.debug("self.max_id_question : %s", self.max_id_question)
# logger.debug("self.dict_questions : %s", self.dict_questions)
# logger.debug("self.max_id_studio_question : %s", self.max_id_studio_question)
# logger.debug("self.dict_studio_questions : %s", self.dict_studio_questions)
logger.debug(" self.var_test : %s", self.var_test)
# q = "Que permet de faire le théorème de Bayes ? Donner un exemple ?"
# r = "Il permet d'inverser des probabilités pourvu qu'on ait des connaissances préalables."
# r_etu = "Si l'on connait P(A), P(B) et P(A|B),le théorème de Bayes nous permet de calculer P(B|A)."
# for i in range(5):
# self.add_studio_question(q, r)
# logger.debug("self.max_id_question : %s", self.max_id_question)
# logger.debug("self.dict_questions : %s", self.dict_questions)
# logger.debug("self.max_id_studio_question : %s", self.max_id_studio_question)
# logger.debug("self.dict_studio_questions : %s", self.dict_studio_questions)
# logger.debug("self.var_test : %s", self.var_test)
logger.debug("On sort de la partie prof")
# self.t_prof_last_modif = time()
frag = Fragment(self.resource_string("templates/studio.html"))
frag.add_javascript(self.resource_string("static/js/src/p3exblock_studio.js"))
frag.initialize_js('P3eXBlock')
return frag
示例5: studio_view
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,
'weight': self.weight,
'max_attempts': self.max_attempts,
'xml_data': self.question_string,
'your_answer_label': self.your_answer_label,
'our_answer_label': self.our_answer_label,
'submit_button_label': self.submit_button_label,
}
html = self.render_template(
'static/html/submit_and_compare_edit.html',
context,
)
frag = Fragment(html)
frag.add_javascript(
self.load_resource('static/js/submit_and_compare_edit.js'),
)
frag.initialize_js('SubmitAndCompareXBlockInitEdit')
return frag
示例6: studio_view
def studio_view(self, context=None): # pylint: disable=unused-argument
"""
Render the OpenAssessment XBlock for editing in Studio.
Args:
context: Not actively used for this view.
Returns:
(Fragment): An HTML fragment for editing the configuration of this XBlock.
"""
rendered_template = get_template(
'openassessmentblock/edit/oa_edit.html'
).render(self.editor_context())
fragment = Fragment(rendered_template)
if settings.DEBUG:
self.add_javascript_files(fragment, "static/js/src/oa_shared.js")
self.add_javascript_files(fragment, "static/js/src/oa_server.js")
self.add_javascript_files(fragment, "static/js/src/studio")
else:
# TODO: switch to add_javascript_url once XBlock resources are loaded from the CDN
fragment.add_javascript(pkg_resources.resource_string(__name__, "static/js/openassessment-studio.min.js"))
js_context_dict = {
"FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST,
}
fragment.initialize_js('OpenAssessmentEditor', js_context_dict)
return fragment
示例7: mentoring_table_view
def mentoring_table_view(self, context=None):
html = render_js_template('templates/html/answer_table.html', {
'self': self,
})
fragment = Fragment(html)
fragment.add_css_url(self.runtime.local_resource_url(self.xblock_container, 'public/css/answer_table.css'))
return fragment
示例8: dashboard_detail_view
def dashboard_detail_view(self, context):
fragment = Fragment()
children_context = context.copy()
target_workgroups = context.get(Constants.TARGET_WORKGROUPS)
target_users = context.get(Constants.TARGET_STUDENTS)
filtered_users = children_context[Constants.FILTERED_STUDENTS]
stages = []
stage_stats = {}
for stage in self.stages:
if not stage.shown_on_detail_view:
continue
stage_fragment = stage.render('dashboard_detail_view', children_context)
stage_fragment.add_frag_resources(fragment)
stages.append({"id": stage.id, 'content': stage_fragment.content})
stage_stats[stage.id] = self._get_stage_completion_details(stage, target_workgroups, target_users)
groups_data = self._build_groups_data(target_workgroups, stage_stats, filtered_users)
visible_groups = [group for group in groups_data if group["group_visible"]]
render_context = {
'activity': self,
'StageState': StageState,
'stages': stages,
'stages_count': len(stages),
'groups': visible_groups,
'filtered_out_workgroups': len(groups_data) - len(visible_groups),
'stage_cell_width_percent': (100 - 30) / float(len(stages)), # 30% is reserved for first column
'assigned_to_groups_label': messages.ASSIGNED_TO_GROUPS_LABEL.format(group_count=len(groups_data))
}
fragment.add_content(self.render_template('dashboard_detail_view', render_context))
return fragment
示例9: studio_view
def studio_view(self, context=None):
html = self.resource_string("static/html/paellavideo_edit.html")
options = "<option value='' >----</option>"
for key in paellaservers.PAELLASERVERS:
if self.server == key["url"]:
options = (
options + "<option value='" + key["url"] + "' selected='selected' >" + key["name"] + "</option>"
)
else:
options = options + "<option value='" + key["url"] + "' >" + key["name"] + "</option>"
selector = u"""
<script type="text/template" id="xblock-equality-template">
</script>
<select name='Server' id='edit_server'>
{}
</select>""".format(
options
)
frag = Fragment(html.format(self=self, selector=selector))
frag.add_javascript(self.resource_string("static/js/src/paellavideo_edit.js"))
frag.initialize_js("paellaXBlock")
return frag
示例10: student_view
def student_view(self, context=None):
"""
Create a fragment used to display the XBlock to a student
`context` is a dictionary used to configure the display (unused).
Returns a `Fragment` object specifying the HTML, CSS and JavaScript to display
"""
href = self.href or ''
display_name = self.display_name or ''
# Make the oEmbed call to get the embed code
try:
embed_code, width, height = self.get_embed_code(href)
html_str = self.resource_string("static/html/officemix.html")
except Exception as ex:
html_str = self.resource_string("static/html/embed_error.html")
frag = Fragment(html_str.format(self=self, exception=cgi.escape(str(ex))))
return frag
# Grab and round the aspect ratio
ratio = decimal.Decimal(float(height) / width * 100.0)
# Construct the HTML
frag = Fragment(html_str.format(
self=self,
embed_code=embed_code,
display_name=cgi.escape(display_name)))
# And construct the CSS
css_str = self.resource_string("static/css/officemix.css")
css_str = string.replace(unicode(css_str), "{aspect_ratio}", cgi.escape(unicode(round(ratio, 2))))
frag.add_css(css_str)
return frag
示例11: student_view
def student_view(self, context):
fragment = Fragment()
contents = []
child_context = {} if not context else copy(context)
child_context['child_of_vertical'] = True
for child in self.get_display_items():
print
print
print "Type(child): ", type(child)
print
print
rendered_child = child.render(STUDENT_VIEW, child_context)
fragment.add_frag_resources(rendered_child)
contents.append({
'id': child.location.to_deprecated_string(),
'content': rendered_child.content
})
fragment.add_content(self.system.render_template('vert_module.html', {
'items': contents,
'xblock_context': context,
}))
return fragment
示例12: studio_view
def studio_view(self, context):
"""temporary for debug number of hosts=0"""
html = self.resource_string("static/html/ssh_edit.html")
frag = Fragment(html.format(self=self))
frag.add_javascript(self.resource_string("static/js/ssh_edit.js"))
frag.initialize_js('SshEditXBlock')
return frag
示例13: studio_view
def studio_view(self, context=None):
template_context = {'lab_proxy_id': self.lab_proxy_id}
if not self.lab_proxy_id:
# fetch the proxies
labs = requests.get(LAB_URL).json()
template_context.update({
'labs': labs,
})
else:
lab_proxy_url = "{}{}/".format(LAB_PROXY_URL, self.lab_proxy_id)
lab_proxy = requests.get(lab_proxy_url).json()
template_context.update({
'lab_proxy': lab_proxy,
})
html = render_template("templates/lab_studio.html", template_context)
frag = Fragment(html)
frag.add_javascript_url(self.runtime.local_resource_url(self, "public/js/labster_lab_studio.js"))
frag.initialize_js('LabsterLabXBlock')
return frag
示例14: error_frag
def error_frag(msg):
""" Build a fragment to display runtime errors. """
context = {'error_msg': msg}
html = loader.render_template('static/html/error.html', context)
frag = Fragment(html)
frag.add_css_url(self.runtime.local_resource_url(self, 'public/css/main.css'))
return frag
示例15: get_url_name_fragment
def get_url_name_fragment(self, caption):
fragment = Fragment()
fragment.add_content(loader.render_template(
"templates/html/url_name.html",
{'url_name': self.url_name, 'caption': caption}
))
return fragment