def student_view(self, context): html = self.resource_string('public/html/student_view.html') fragment = Fragment(html.format(self=self)) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/student_view.js')) fragment.add_css(self.runtime.local_resource_url(self, 'public/css/jsav_xblock.css')) fragment.initialize_js('JSAVXBlock') return fragment
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 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
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(): values = tag.get_values() current_value = self.saved_tags.get(tag.name, None) if current_value is not None and current_value not in values: values.insert(0, current_value) tags.append({ 'key': tag.name, 'title': tag.title, 'values': values, 'current_value': current_value }) fragment = Fragment(render_to_string('structured_tags_block.html', {'tags': 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'')
def student_view(self, context=None): """ The primary view of the AnimationXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/animation.html") frag = Fragment( html.format(height=self.height, textheight=self.textheight, width=self.width, inner_width=self.width - 20, animation=json.dumps(self.animation), position=self.position, max_position=self.max_position)) # frag.add_javascript_url("//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js") frag.add_css_url( "//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" ) frag.add_css( self.resource_string("static/css/jquery.ui.labeledslider.css")) frag.add_javascript_url( "//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js") frag.add_javascript( self.resource_string("static/js/src/jquery.ui.labeledslider.js")) frag.add_css(self.resource_string("static/css/animation.css")) frag.add_javascript(self.resource_string("static/js/src/animation.js")) frag.initialize_js('AnimationXBlock') return frag
def mentoring_view(self, context=None): """ Render this XBlock within a mentoring block. """ context = context.copy() if context else {} student_submissions_key = context.get('student_submissions_key') context['title'] = self.display_name context['description'] = self.description if student_submissions_key: location = self.location.replace( branch=None, version=None) # Standardize the key in case it isn't already target_key = { 'student_id': student_submissions_key, 'course_id': unicode(location.course_key), 'item_id': self.name, 'item_type': u'pb-answer', } submissions = sub_api.get_submissions(target_key, limit=1) try: context['student_input'] = submissions[0]['answer'] except IndexError: context['student_input'] = None else: context['student_input'] = self.student_input html = loader.render_template('templates/html/answer_read_only.html', context) fragment = Fragment(html) fragment.add_css_url( self.runtime.local_resource_url(self, self.css_path)) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/answer_recap.js')) fragment.initialize_js('AnswerRecapBlock') return fragment
def student_view(self, context): """ Render the contents of the chosen condition for students, and all the conditions for staff. """ # When rendering a Studio preview, render all of the block's children if context and context.get('runtime_type', None) == 'studio': return self.studio_preview_view(context) if self.child is None: # raise error instead? In fact, could complain on descriptor load... return Fragment(content=u"<div>Nothing here. Move along.</div>") if self.system.user_is_staff: return self._staff_view(context) else: child_fragment = self.child.render('student_view', context) fragment = Fragment(self.system.render_template('split_test_student_view.html', { 'child_content': child_fragment.content, 'child_id': self.child.scope_ids.usage_id, })) fragment.add_frag_resources(child_fragment) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_student.js')) fragment.initialize_js('SplitTestStudentView') return fragment
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'')
def student_view(self, context=None): """ The primary view of the RecommenderXBlock, shown to students when viewing courses. """ print "entered" if not self.recommendations: self.recommendations = self.default_recommendations if not self.recommendations: self.recommendations = [] if not self.template_lookup: self.template_lookup = TemplateLookup() self.template_lookup.put_string("recommender.html", self.resource_string("static/html/recommender.html")) self.template_lookup.put_string("resourcebox.html", self.resource_string("static/html/resourcebox.html")) # Ideally, we'd estimate score based on votes, such that items with 1 vote have a sensible ranking (rather than a perfect rating) # resources = [{'id' : r['id'], 'title' : r['title'], "votes" : r['upvotes'] - r['downvotes'], 'url' : r['url'], 'description' : r['description']} for r in self.recommendations] resources = sorted(resources, key = lambda r: r['votes'], reverse=True) frag = Fragment(self.template_lookup.get_template("recommender.html").render(resources = resources, upvotes = self.upvotes, downvotes = self.downvotes, flagId = self.flagId, flagReason = self.flagReason)) frag.add_css_url("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css") frag.add_javascript_url("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js") frag.add_css(self.resource_string("static/css/recommender.css")) frag.add_javascript(self.resource_string("static/js/src/recommender.js")) frag.initialize_js('RecommenderXBlock') return frag
def student_view(self, context): """ The main view of this XBlock. """ template = template_engine.get_template('student_view.html') html = template.render({ "title": self.display_name, "instructions": self.instructions, "text_parts": self.text_parts, "selected_part_index": self.part_selected, "wrong_part_index": self.wrong_part_index if self.student_has_answered else None, }) fragment = Fragment(html) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/style.css')) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/client.js')) fragment.initialize_js('GrammarianXBlock', self.get_current_state()) return fragment
def student_view(self, context=None): name = self.__class__.__name__ as_template = context.get(ContextConstants.AS_TEMPLATE, True) if context is not None else True if str(self.type) not in self.valid_types: raise ValueError(u'Invalid value for {}.type: `{}`'.format( name, self.type)) template_path = 'templates/html/{}_{}.html'.format( name.lower(), self.type) render_function = loader.custom_render_js_template if as_template else loader.render_template html = render_function(template_path, { 'self': self, 'custom_choices': self.custom_choices }) fragment = Fragment(html) fragment.add_css( loader.render_template('public/css/questionnaire.css', {'self': self})) fragment.add_javascript_url( self.runtime.local_resource_url(self.xblock_container, 'public/js/questionnaire.js')) fragment.initialize_js(name) return fragment
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
def student_view(self, context=None): fragment = Fragment() if getattr(self.xmodule_runtime, 'is_author_mode', False): fragment.add_content(render_mako_template( 'templates/discussion/_discussion_inline_studio.html', {'discussion_id': self.discussion_id} )) fragment.add_css(load_resource('static/discussion/css/discussion-studio.css')) return fragment discussion_service = self.xmodule_runtime.service(self, 'discussion') context = discussion_service.get_inline_template_context(self.discussion_id) context['discussion_id'] = self.discussion_id fragment.add_content(render_mako_template( 'templates/discussion/_discussion_inline.html', context )) fragment.add_javascript(render_template('static/discussion/js/discussion_inline.js', { 'course_id': self.course_id })) fragment.add_content(render_mustache_templates()) for url in get_js_urls(): fragment.add_javascript_url(url) for url in get_css_urls(): fragment.add_css_url(url) fragment.initialize_js('DiscussionInlineBlock') return fragment
def student_view(self, context): """ Player view, displayed to the student """ sources = filter(None, self.sources.split('\n')) if self.sources else '' audio_download_url = sources[0] if sources else None # Add the MIME type if we think we know it. annotated_sources = [] for source in sources: type = get_path_mimetype(source) annotated_sources.append((source, type)) fragment = Fragment() fragment.add_content(loader.render_mako_template( 'templates/html/audio.html', { 'audio_id': self.audio_id, 'sources': annotated_sources, 'allow_audio_download': self.allow_audio_download, 'audio_download_url': audio_download_url })) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/audio.css')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mediaelement.player.min.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mediaelement.player.min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/audio.js')) fragment.initialize_js("AudioBlock") return fragment
def studio_view(self, context): """ Studio edit view """ root = etree.fromstring(self.data.replace('&', '&')) items = [] for child in root: text_data = child.find('link').text if child.tag == 'document': text_data = urllib.quote(text_data, '') try: full_screen_link = child.find("full_screen_link").text except: full_screen_link = "" full_screen_link = full_screen_link if full_screen_link else '' description = child.find('description') description1 = ET.tostring(description) description1 = description1.replace('<description>', '') description1 = description1.replace('</description>', '') description1 = description1.replace('&', '&') description1 = urllib2.unquote( HTMLParser.HTMLParser().unescape(description1)) width = child.attrib.get('width', '100%') height = child.attrib.get('height', '625') items.append((child.tag, text_data, width, height, description1, full_screen_link)) fragment = Fragment() context = { 'data': self.data, 'items': items, 'display_name': self.display_name } fragment = Fragment() fragment.add_javascript_url( "https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js" ) fragment.add_css_url( "https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" ) fragment.add_content( render_template('templates/html/carousel_edit.html', context)) fragment.add_javascript( load_resource('public/js/jquery-ui-1.10.4.custom.js')) fragment.add_javascript(load_resource('public/js/tinymce.min.js')) fragment.add_javascript(load_resource('public/js/carousel_edit.js')) fragment.add_javascript(load_resource('public/js/carousel.js')) fragment.initialize_js('CarouselEditBlock') return fragment
def student_view(self, context): """ 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. """ provider, embed_code = self.get_embed_code_for_url(self.href) # Load the HTML fragment from within the package and fill in the template html_str = pkg_resources.resource_string( __name__, "static/html/simplevideo.html") frag = Fragment( unicode(html_str).format(self=self, embed_code=embed_code)) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/simplevideo.css") frag.add_css(unicode(css_str)) # Load JS if provider == 'vimeo.com': # Load the Froogaloop library from vimeo CDN. frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js") js_str = pkg_resources.resource_string(__name__, "static/js/simplevideo.js") frag.add_javascript(unicode(js_str)) frag.initialize_js('SimpleVideoBlock') return frag
def studio_view(self, context): """ Editing view in Studio """ js_templates = load_resource('/templates/html/js_templates.html') context = { 'js_templates': js_templates, 'self': self, 'data': urllib.quote(json.dumps(self.data)), } fragment = Fragment() fragment.add_content(render_template('/templates/html/drag_and_drop_edit.html', context)) css_urls = ( 'public/css/vendor/jquery-ui-1.10.4.custom.min.css', 'public/css/drag_and_drop_edit.css' ) js_urls = ( 'public/js/vendor/jquery-ui-1.10.4.custom.min.js', 'public/js/vendor/jquery.html5-placeholder-shim.js', 'public/js/vendor/handlebars-v1.1.2.js', 'public/js/drag_and_drop_edit.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url(self, css_url)) for js_url in js_urls: fragment.add_javascript_url(self.runtime.local_resource_url(self, js_url)) fragment.initialize_js('DragAndDropEditBlock') return fragment
def student_view(self, context): """ Renders parameters to template. """ context = { 'course_key': self.runtime.course_id, 'display_name': self.display_name_with_default, '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, } fragment = Fragment( self.system.render_template('textannotation.html', context)) 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
def build_fragment( self, html_source=None, paths_css=[], paths_js=[], urls_css=[], urls_js=[], fragment_js=None, ): # pylint: disable=dangerous-default-value, too-many-arguments """ Assemble the HTML, JS, and CSS for an XBlock fragment """ fragment = Fragment(html_source) for url in urls_css: fragment.add_css_url(url) for path in paths_css: url = self.get_resource_url(path) fragment.add_css_url(url) for url in urls_js: fragment.add_javascript_url(url) for path in paths_js: url = self.get_resource_url(path) fragment.add_javascript_url(url) if fragment_js: fragment.initialize_js(fragment_js) return fragment
def student_view(self, context=None): """ The primary view of the BibblioXBlock, shown to students when viewing courses. """ idArray = self.scope_ids.usage_id._to_string().split('@') xblock_id = idArray[len(idArray) - 1] html = self.resource_string("static/html/bibblio.html") frag = Fragment(html.format(self=self, xblock_id=xblock_id)) frag.add_css(self.resource_string("static/css/bibblio.css")) frag.add_css( self.resource_string("public/css/bib-related-content.css")) frag.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/underscore-min.js')) frag.add_javascript_url( self.runtime.local_resource_url( self, 'public/js/bib-related-content.js')) frag.add_javascript(self.resource_string("static/js/bibblio.js")) frag.initialize_js('BibblioXBlock', {'xblockId': xblock_id}) return frag
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
def student_view(self, context): """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content( render_template('/templates/html/drag_and_drop.html')) css_urls = ('public/css/vendor/jquery-ui-1.10.4.custom.min.css', 'public/css/drag_and_drop.css') js_urls = ( 'public/js/vendor/jquery-ui-1.10.4.custom.min.js', 'public/js/vendor/jquery-ui-touch-punch-0.2.3.min.js', # Makes it work on touch devices 'public/js/vendor/virtual-dom-1.3.0.min.js', 'public/js/drag_and_drop.js', 'public/js/view.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url( self, css_url)) for js_url in js_urls: fragment.add_javascript_url( self.runtime.local_resource_url(self, js_url)) fragment.initialize_js('DragAndDropBlock') return fragment
def build_fragment( self, path_html='', paths_css=[], paths_js=[], urls_css=[], urls_js=[], fragment_js=None, context=None, ): """ Assemble the HTML, JS, and CSS for an XBlock fragment """ # If no context is provided, convert self.fields into a dict context = context or { key: getattr(self, key) for key in self.fields if key not in DEFAULT_FIELDS } html_source = self.get_resource_string(path_html) html_source = html_source.format(**context) fragment = Fragment(html_source) for path in paths_css: url = self.get_resource_url(path) fragment.add_css_url(url) for path in paths_js: url = self.get_resource_url(path) fragment.add_javascript_url(url) for url in urls_css: fragment.add_css_url(url) for url in urls_js: fragment.add_javascript_url(url) if fragment_js: fragment.initialize_js(fragment_js) return fragment
def student_view(self, context=None): fragment = Fragment() if getattr(self.xmodule_runtime, 'is_author_mode', False): fragment.add_content( render_mako_template( 'templates/discussion/_discussion_inline_studio.html', {'discussion_id': self.discussion_id})) fragment.add_css( load_resource('static/discussion/css/discussion-studio.css')) return fragment discussion_service = self.xmodule_runtime.service(self, 'discussion') context = discussion_service.get_inline_template_context( self.discussion_id) context['discussion_id'] = self.discussion_id fragment.add_content( render_mako_template( 'templates/discussion/_discussion_inline.html', context)) fragment.add_javascript( render_template('static/discussion/js/discussion_inline.js', {'course_id': self.course_id})) fragment.add_content(render_mustache_templates()) for url in get_minified_js_urls(): fragment.add_javascript_url(url) for url in get_css_urls(): fragment.add_css_url(url) fragment.initialize_js('DiscussionInlineBlock') return fragment
def student_view(self, context): """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content( loader.render_django_template('/templates/html/drag_and_drop.html', i18n_service=self.i18n_service)) css_urls = ('public/css/drag_and_drop.css', ) js_urls = [ 'public/js/vendor/virtual-dom-1.3.0.min.js', 'public/js/drag_and_drop.js', ] statici18n_js_url = self._get_statici18n_js_url() if statici18n_js_url: js_urls.append(statici18n_js_url) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url( self, css_url)) for js_url in js_urls: fragment.add_javascript_url( self.runtime.local_resource_url(self, js_url)) self.include_theme_files(fragment) fragment.initialize_js('DragAndDropBlock', self.student_view_data()) return fragment
def author_edit_view(self, context): """ Add some HTML to the author view that allows authors to add child blocks. """ fragment = Fragment( u'<div class="mentoring">' ) # This DIV is needed for CSS to apply to the previews self.render_children(context, fragment, can_reorder=True, can_add=False) fragment.add_content(u'</div>') fragment.add_content( loader.render_template('templates/html/mentoring_add_buttons.html', {})) fragment.add_content( loader.render_template('templates/html/mentoring_url_name.html', {"url_name": self.url_name})) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/problem-builder.css')) fragment.add_css_url( self.runtime.local_resource_url( self, 'public/css/problem-builder-edit.css')) fragment.add_css_url( self.runtime.local_resource_url( self, 'public/css/problem-builder-tinymce-content.css')) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/util.js')) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/mentoring_edit.js')) fragment.initialize_js('MentoringEditComponents') return fragment
def student_view(self, context): """ Renders parameters to template. """ extension = self._get_extension(self.sourceurl) context = { 'course_key': self.runtime.course_id, 'display_name': self.display_name_with_default, 'instructions_html': self.instructions, 'sourceUrl': self.sourceurl, 'typeSource': extension, 'poster': self.poster_url, 'content_html': self.content, 'token': retrieve_token(self.user_email, self.annotation_token_secret), 'annotation_storage': self.annotation_storage_url, 'default_tab': self.default_tab, 'instructor_email': self.instructor_email, 'annotation_mode': self.annotation_mode, } fragment = Fragment( self.system.render_template('videoannotation.html', context)) fragment.add_javascript_url( "/static/js/vendor/tinymce/js/tinymce/tinymce.full.min.js") fragment.add_javascript_url( "/static/js/vendor/tinymce/js/tinymce/jquery.tinymce.min.js") return fragment
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_configured = not self.user_partition_id == SplitTestFields.no_partition_selected['value'] 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': 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
def student_view(self, context=None): # pylint: disable=no-member """ The primary view of the StaffGradedAssignmentXBlock, shown to students when viewing courses. """ context = { "student_state": json.dumps(self.student_state()), "id": self.location.name.replace('.', '_'), "max_file_size": getattr( settings, "STUDENT_FILEUPLOAD_MAX_SIZE", self.STUDENT_FILEUPLOAD_MAX_SIZE ) } if self.show_staff_grading_interface(): context['is_course_staff'] = True self.update_staff_debug_context(context) fragment = Fragment() fragment.add_content( render_template( 'templates/staff_graded_assignment/show.html', context ) ) fragment.add_css(_resource("static/css/edx_sga.css")) fragment.add_javascript(_resource("static/js/src/edx_sga.js")) fragment.add_javascript_url("//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js") fragment.add_css_url("//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css") fragment.initialize_js('StaffGradedAssignmentXBlock', {'blockid': context['id']}) return fragment
def _render_view(self, context, view): """ Actually renders a view """ fragment = Fragment() child_contents = [] for child_id in self.children: child = self.runtime.get_block(child_id) if child is None: # child should not be None but it can happen due to bugs or permission issues child_contents.append(u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))) else: child_fragment = self._render_child_fragment(child, context, view) fragment.add_frag_resources(child_fragment) child_contents.append(child_fragment.content) fragment.add_content(loader.render_template('templates/html/step.html', { 'self': self, 'title': self.display_name, 'show_title': self.show_title, 'child_contents': child_contents, })) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/step.js')) fragment.initialize_js('MentoringStepBlock') return fragment
def student_view(self, context=None): name = getattr(self, "unmixed_class", self.__class__).__name__ template_path = 'templates/html/{}.html'.format(name.lower()) context = context.copy() if context else {} context['self'] = self context['custom_choices'] = self.custom_choices context['hide_header'] = context.get('hide_header', False) or not self.show_title fragment = Fragment(loader.render_template(template_path, context)) # If we use local_resource_url(self, ...) the runtime may insert many identical copies # of questionnaire.[css/js] into the DOM. So we use the mentoring block here if possible. block_with_resources = self.get_parent() from .mentoring import MentoringBlock # We use an inline import here to avoid a circular dependency with the .mentoring module. if not isinstance(block_with_resources, MentoringBlock): block_with_resources = self fragment.add_css_url( self.runtime.local_resource_url(block_with_resources, 'public/css/questionnaire.css')) fragment.add_javascript_url( self.runtime.local_resource_url(block_with_resources, 'public/js/questionnaire.js')) fragment.initialize_js(name) return fragment
def student_view(self, context): """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content(loader.render_template('/templates/html/drag_and_drop.html')) css_urls = ( 'public/css/vendor/jquery-ui-1.10.4.custom.min.css', 'public/css/vendor/bootstrap.min.css', 'public/css/drag_and_drop.css' ) js_urls = ( 'public/js/vendor/jquery-ui-1.10.4.custom.min.js', 'public/js/vendor/jquery-ui-touch-punch-0.2.3.min.js', # Makes it work on touch devices 'public/js/vendor/virtual-dom-1.3.0.min.js', 'public/js/drag_and_drop.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url(self, css_url)) for js_url in js_urls: fragment.add_javascript_url(self.runtime.local_resource_url(self, js_url)) self.include_theme_files(fragment) fragment.initialize_js('DragAndDropBlock', self.get_configuration()) return fragment
def student_view(self, context=None): """ The primary view of the ProfileXBlock, shown to students when viewing courses. """ photo_url = self.runtime.local_resource_url(self, 'public/assets/profile.png') if self.photo_storage.exists("profile.png"): photo_url = self.photo_storage.get_url("profile.png", 600) params = { 'PHOTO_URL': photo_url } for asset in assets: params[asset] = self.runtime.local_resource_url(self, os.path.join("public/assets",asset)) html = replace_template(self.resource_string("static/html/profile.html"), params) frag = Fragment(html) frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js') #frag.add_javascript_url(self.runtime.local_resource_url(self, 'public/3rdParty/mustache.js')) frag.add_css_url('//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/css/jquery-ui.min.css') #frag.add_css_url(self.runtime.local_resource_url(self, 'public/3rdParty/jquery-ui.css')) frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js') # frag.add_javascript_url(self.runtime.local_resource_url(self, 'public/3rdParty/jquery-ui.min.js')) # TODO: This would give nicer selects # frag.add_css(self.resource_string("static/3rdparty/jquery.dropdown.css")) # frag.add_javascript(self.resource_string("static/3rdparty/jquery.dropdown.min.js")) frag.add_css(self.resource_string("static/css/profile.css")) frag.add_javascript(self.resource_string("static/js/src/profile.js")) profile_config = profile_json.profile_config if self.view.lower() == "peer": profile_config = profile_json.peer_profile_config frag.initialize_js('ProfileXBlock', {'profile_data': self.user_profile, 'profile_config':profile_config}) return frag
def student_view(self, context): """ 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. """ provider, embed_code = self.get_embed_code_for_url(self.href) # Load the HTML fragment from within the package and fill in the template html_str = pkg_resources.resource_string(__name__, "static/html/simplevideo.html") frag = Fragment(unicode(html_str).format(self=self, embed_code=embed_code)) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/simplevideo.css") frag.add_css(unicode(css_str)) # Load JS if provider == 'vimeo.com': # Load the Froogaloop library from vimeo CDN. frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js") js_str = pkg_resources.resource_string(__name__, "static/js/simplevideo.js") frag.add_javascript(unicode(js_str)) frag.initialize_js('SimpleVideoBlock') return frag
def student_view(self, context): """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content( loader.render_template('/templates/html/drag_and_drop.html')) css_urls = ('public/css/drag_and_drop.css', ) js_urls = ( 'public/js/vendor/virtual-dom-1.3.0.min.js', 'public/js/drag_and_drop.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url( self, css_url)) for js_url in js_urls: fragment.add_javascript_url( self.runtime.local_resource_url(self, js_url)) self.include_theme_files(fragment) fragment.initialize_js('DragAndDropBlock', self.get_configuration()) return fragment
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_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_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, '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)) })) fragment.add_javascript_url( self.runtime.local_resource_url( self, 'public/js/vertical_student_view.js')) fragment.initialize_js('VerticalStudentView') return fragment
def studio_view(self, context): """ Editing view in Studio """ js_templates = loader.load_unicode('/templates/html/js_templates.html') # Get an 'id_suffix' string that is unique for this block. # We append it to HTML element ID attributes to ensure multiple instances of the DnDv2 block # on the same page don't share the same ID value. # We avoid using ID attributes in preference to classes, but sometimes we still need IDs to # connect 'for' and 'aria-describedby' attributes to the associated elements. id_suffix = self._get_block_id() js_templates = js_templates.replace('{{id_suffix}}', id_suffix) context = { 'js_templates': js_templates, 'id_suffix': id_suffix, 'fields': self.fields, 'self': self, 'data': urllib.quote(json.dumps(self.data)), } fragment = Fragment() fragment.add_content( loader.render_template('/templates/html/drag_and_drop_edit.html', context)) css_urls = ('public/css/drag_and_drop_edit.css', ) js_urls = ( 'public/js/vendor/handlebars-v1.1.2.js', 'public/js/drag_and_drop_edit.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url( self, css_url)) for js_url in js_urls: fragment.add_javascript_url( self.runtime.local_resource_url(self, js_url)) # Do a bit of manipulation so we get the appearance of a list of zone options on # items that still have just a single zone stored items = self.data.get('items', []) for item in items: zones = self.get_item_zones(item['id']) # Note that we appear to be mutating the state of the XBlock here, but because # the change won't be committed, we're actually just affecting the data that # we're going to send to the client, not what's saved in the backing store. item['zones'] = zones item.pop('zone', None) fragment.initialize_js( 'DragAndDropEditBlock', { 'data': self.data, 'target_img_expanded_url': self.target_img_expanded_url, 'default_background_image_url': self.default_background_image_url, }) return fragment
def _staff_view(self, context): """ Render the staff view for a split test module. """ fragment = Fragment() active_contents = [] inactive_contents = [] for child_location in self.children: # pylint: disable=no-member child_descriptor = self.get_child_descriptor_by_location( child_location) child = self.system.get_module(child_descriptor) rendered_child = child.render(STUDENT_VIEW, context) fragment.add_frag_resources(rendered_child) group_name, updated_group_id = self.get_data_for_vertical(child) if updated_group_id is None: # inactive group group_name = child.display_name updated_group_id = [ g_id for g_id, loc in self.group_id_to_child.items() if loc == child_location ][0] inactive_contents.append({ 'group_name': _(u'{group_name} (inactive)').format( group_name=group_name), 'id': child.location.to_deprecated_string(), 'content': rendered_child.content, 'group_id': updated_group_id, }) continue active_contents.append({ 'group_name': group_name, 'id': child.location.to_deprecated_string(), 'content': rendered_child.content, 'group_id': updated_group_id, }) # Sort active and inactive contents by group name. sorted_active_contents = sorted(active_contents, key=itemgetter('group_name')) sorted_inactive_contents = sorted(inactive_contents, key=itemgetter('group_name')) # Use the new template fragment.add_content( self.system.render_template( 'split_test_staff_view.html', { 'items': sorted_active_contents + sorted_inactive_contents, })) fragment.add_css('.split-test-child { display: none; }') fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/split_test_staff.js')) fragment.initialize_js('ABTestSelector') return fragment
def student_view(self, context): """ Lab view, displayed to the student """ root = ET.fromstring(self.data) items = [] for child in root: if child.tag == 'doc': child.text = urllib.quote(child.text, '') width = child.attrib.get('width', '100%') height = child.attrib.get('height', '625') items.append((child.tag, child.text, width, height)) fragment = Fragment() context = { 'items': items, } fragment.add_content(render_template('/templates/html/carousel.html', context)) fragment.add_javascript(load_resource('public/js/jquery-ui-1.10.4.custom.js')) fragment.add_css(load_resource('public/css/responsive-carousel.css')) fragment.add_css(load_resource('public/css/responsive-carousel.slide.css')) fragment.add_javascript(load_resource('public/js/responsive-carousel.js')) fragment.add_javascript(load_resource('public/js/responsive-carousel.loop.js')) fragment.add_css_url("https://vjs.zencdn.net/4.5.1/video-js.css") fragment.add_javascript_url("https://vjs.zencdn.net/4.5.1/video.js") fragment.add_javascript(load_resource('public/js/youtube.js')) fragment.add_javascript('function CarouselBlock(runtime, element) {$(".carousel").carousel();console.log("OK");}') fragment.initialize_js('CarouselBlock') return fragment
def student_view(self, context): """ Render the contents of the chosen condition for students, and all the conditions for staff. """ # When rendering a Studio preview, render all of the block's children if context and context.get('runtime_type', None) == 'studio': return self.studio_preview_view(context) if self.child is None: # raise error instead? In fact, could complain on descriptor load... return Fragment(content=u"<div>Nothing here. Move along.</div>") if self.system.user_is_staff: return self._staff_view(context) else: child_fragment = self.child.render('student_view', context) fragment = Fragment( self.system.render_template( 'split_test_student_view.html', { 'child_content': child_fragment.content, 'child_id': self.child.scope_ids.usage_id, })) fragment.add_frag_resources(child_fragment) fragment.add_javascript_url( self.runtime.local_resource_url( self, 'public/js/split_test_student.js')) fragment.initialize_js('SplitTestStudentView') return fragment
def student_view(self, context=None): """ The primary view of the MultipleFileUploadXBlock, shown to students when viewing courses. """ # Ideally we would do this when the score is entered. This write on # read pattern is pretty bad. Currently, though, the code in the # courseware application that handles the grade event will puke if the # user_id for the event is other than the logged in user. if not self.score_published and self.score_approved: self.runtime.publish(self, 'grade', { 'value': self.score, 'max_value': self.max_score(), }) self.score_published = True context = { "student_state": json.dumps(self.student_state()), "id": self.location.name.replace('.', '_') } if self.show_staff_grading_interface(): context['is_course_staff'] = True self.update_staff_debug_context(context) fragment = Fragment() fragment.add_content( render_template('templates/multiple_file_upload/show.html', context)) fragment.add_css(_resource("static/css/edx_mfu.css")) fragment.add_javascript(_resource("static/js/src/edx_mfu.js")) #Fragment.add_javascript(_resource("static/js/vendor/date.js")) fragment.add_javascript_url("/static/js/vendor/date.js") fragment.initialize_js('MultipleFileUploadXBlock') return fragment
def studio_view(self, context): """ Editing view in Studio """ js_templates = load_resource('/templates/html/js_templates.html') context = { 'js_templates': js_templates, 'self': self, 'data': urllib.quote(json.dumps(self.data)), } fragment = Fragment() fragment.add_content( render_template('/templates/html/drag_and_drop_edit.html', context)) css_urls = ('public/css/vendor/jquery-ui-1.10.4.custom.min.css', 'public/css/drag_and_drop_edit.css') js_urls = ( 'public/js/vendor/jquery-ui-1.10.4.custom.min.js', 'public/js/vendor/jquery.html5-placeholder-shim.js', 'public/js/vendor/handlebars-v1.1.2.js', 'public/js/drag_and_drop_edit.js', ) for css_url in css_urls: fragment.add_css_url(self.runtime.local_resource_url( self, css_url)) for js_url in js_urls: fragment.add_javascript_url( self.runtime.local_resource_url(self, js_url)) fragment.initialize_js('DragAndDropEditBlock') return fragment
def build_fragment( self, html_source=None, paths_css=[], paths_js=[], urls_css=[], urls_js=[], fragment_js=None, ): # pylint: disable=dangerous-default-value, too-many-arguments """ Assemble the HTML, JS, and CSS for an XBlock fragment """ xblockId = self._get_xblock_id() fragment = Fragment(unicode(html_source, 'utf-8')) for url in urls_css: fragment.add_css_url(url) for path in paths_css: url = self.get_resource_url(path) fragment.add_css_url(url) for url in urls_js: fragment.add_javascript_url(url) for path in paths_js: url = self.get_resource_url(path) fragment.add_javascript_url(url) if fragment_js: fragment.initialize_js(fragment_js, { 'freetextBlockId': xblockId, }) return fragment
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(): values = tag.get_values() current_value = self.saved_tags.get(tag.name, None) if current_value is not None and current_value not in values: values.insert(0, current_value) tags.append({ 'key': tag.name, 'title': tag.title, 'values': values, 'current_value': current_value }) fragment = Fragment( render_to_string('structured_tags_block.html', { 'tags': 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'')
def problem_view(self, context=None): """Renders the problem view. The view is specific to whether or not this problem was attempted, and, if so, if it was answered correctly. """ correct = self.left == self.right # TODO: I originally named this class="data", but that conflicted with # the CSS on the page! :( We might have to do something to namespace # things. # TODO: Should we have a way to spit out JSON islands full of data? # Note the horror of mixed Python-Javascript data below... content = string.Template(self.content).substitute(**context) result = Fragment(u""" <span class="mydata" data-attempted='{self.attempted}' data-correct='{correct}'> {content} <span class='indicator'></span> </span> """.format(self=self, content=content, correct=correct) ) # TODO: This is a runtime-specific URL. But if each XBlock ships their # own copy of underscore.js, we won't be able to uniquify them. # Perhaps runtimes can offer a palette of popular libraries so that # XBlocks can refer to them in XBlock-standard ways? result.add_javascript_url("/static/js/vendor/underscore-min.js") # TODO: The image tag here needs a magic URL, not a hard-coded one. result.add_resource(u""" <script type="text/template" id="xblock-equality-template"> <% if (attempted !== "True") { %> (Not attempted) <% } else { %> <img src="/resource/workbench/images/<%= (correct === "True") ? "correct" : "incorrect" %>-icon.png"> <% } %> </script> """, "text/html") result.add_javascript(""" function EqualityCheckerBlock(runtime, element) { var template = _.template($("#xblock-equality-template").html()); function render() { var data = $("span.mydata", element).data(); $("span.indicator", element).html(template(data)); } render(); return { handle_check: function(result) { $("span.mydata", element) .data("correct", result ? "True" : "False") .data("attempted", "True"); render(); } } } """) result.initialize_js('EqualityCheckerBlock') return result
def student_view(self, context): fragment = Fragment() children_contents = [] for child_id in self.children: child = self.runtime.get_block(child_id) if child is None: # child should not be None but it can happen due to bugs or permission issues child_content = u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component.")) elif not isinstance(child, MentoringMessageBlock): child_fragment = self._render_child_fragment(child, context, view='mentoring_view') fragment.add_frag_resources(child_fragment) child_content = child_fragment.content children_contents.append(child_content) fragment.add_content(loader.render_template('templates/html/mentoring_with_steps.html', { 'self': self, 'title': self.display_name, 'show_title': self.show_title, 'children_contents': children_contents, })) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/problem-builder.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_with_steps.js')) fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html") fragment.add_resource(loader.load_unicode('templates/html/mentoring_review_templates.html'), "text/html") self.include_theme_files(fragment) fragment.initialize_js('MentoringWithStepsBlock') return fragment
def student_view(self, context): """ Renders the student view of the block in the LMS. """ fragment = Fragment() contents = [] child_context = {} if not context else copy(context) child_context['child_of_vertical'] = True # pylint: disable=no-member for child in self.get_display_items(): 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, 'show_bookmark_button': True, 'bookmarked': child_context['bookmarked'], 'bookmark_id': "{},{}".format(child_context['username'], unicode(self.location)) })) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vertical_student_view.js')) fragment.initialize_js('VerticalStudentView') return fragment
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
def student_view(self, context=None): """ The primary view of the ConceptXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/concept.html")#.replace("PLACEHOLDER_FOR_CONCEPT_MAP",json.dumps(self.concept_map)) cm = self.concept_map if not cm: cm = '{"required":[], "taught":[], "exercised":[]}' # These three lines are not strictly required, but they do # make the code more robust if, for whatever reason, the # storage ends up with nothing for the server. The client # still doesn't work without a valid server, but we don't get # an exception, so we're more likely to be able to get far # enough to fix it. server = self.server if not server: server = "" frag = Fragment(html.replace("PLACEHOLDER_FOR_CONCEPT_MAP",cm).replace("SERVER", server)) frag.add_css_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css") frag.add_css(self.resource_string("static/css/concept.css")) frag.add_javascript_url("http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js") frag.add_javascript_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js") frag.add_javascript(self.resource_string("static/js/concept.js")) frag.initialize_js('ConceptXBlock') return frag
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 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
def student_view(self, context): """ Generate the html code 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. """ provider, embed_code = self.get_embed_code_for_url(self.href) # Retrieve HTML code for video iframe html_code = pkg_resources.resource_string(__name__, "static/html/cnvideo.html") frag = Fragment(unicode(html_code).format(self=self, embed_code=embed_code)) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/cnvideo.css") frag.add_css(css_str) # Load vimeo JS API and custom js for watching views if provider == "vimeo.com": frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js") js_str = pkg_resources.resource_string(__name__, "static/js/cnvideo.js") frag.add_javascript(unicode(js_str)) frag.initialize_js("cnVideoBlock") return frag
def student_view(self, context): """ Renders parameters to template. """ extension = self._get_extension(self.sourceurl) context = { 'course_key': self.runtime.course_id, 'display_name': self.display_name_with_default, 'instructions_html': self.instructions, 'sourceUrl': self.sourceurl, 'typeSource': extension, 'poster': self.poster_url, 'content_html': self.content, 'token': retrieve_token(self.user_email, self.annotation_token_secret), '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('videoannotation.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
def build_fragment(self, path_html='', paths_css=[], paths_js=[], urls_css=[], urls_js=[], fragment_js=None, context=None, ): """ Assemble the HTML, JS, and CSS for an XBlock fragment """ html_source = self.get_resource_string(path_html) html_source = html_source.format( self=self, **context ) fragment = Fragment(html_source) for url in urls_css: fragment.add_css_url(url) for path in paths_css: url = self.get_resource_url(path) fragment.add_css_url(url) for url in urls_js: fragment.add_javascript_url(url) for path in paths_js: url = self.get_resource_url(path) fragment.add_javascript_url(url) if fragment_js: fragment.initialize_js(fragment_js) return fragment
def _staff_view(self, context): """ Render the staff view for a split test module. """ fragment = Fragment() contents = [] for group_id in self.group_id_to_child: child_location = self.group_id_to_child[group_id] child_descriptor = self.get_child_descriptor_by_location(child_location) child = self.system.get_module(child_descriptor) rendered_child = child.render(STUDENT_VIEW, context) fragment.add_frag_resources(rendered_child) contents.append({ 'group_id': group_id, 'id': child.location.to_deprecated_string(), 'content': rendered_child.content }) # Use the new template fragment.add_content(self.system.render_template('split_test_staff_view.html', { 'items': contents, })) fragment.add_css('.split-test-child { display: none; }') fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_staff.js')) fragment.initialize_js('ABTestSelector') return fragment
def build_fragment( self, path_html='', paths_css=[], paths_js=[], urls_css=[], urls_js=[], fragment_js=None, context=None, ): """ Assemble the HTML, JS, and CSS for an XBlock fragment """ html_source = self.get_resource_string(path_html) html_source = html_source.format(self=self, **context) fragment = Fragment(html_source) for url in urls_css: fragment.add_css_url(url) for path in paths_css: url = self.get_resource_url(path) fragment.add_css_url(url) for url in urls_js: fragment.add_javascript_url(url) for path in paths_js: url = self.get_resource_url(path) fragment.add_javascript_url(url) if fragment_js: fragment.initialize_js(fragment_js) return fragment
def mentoring_view(self, context=None): """ Render this XBlock within a mentoring block. """ context = context.copy() if context else {} student_submissions_key = context.get('student_submissions_key') context['title'] = self.display_name context['description'] = self.description if student_submissions_key: location = self.location.replace(branch=None, version=None) # Standardize the key in case it isn't already target_key = { 'student_id': student_submissions_key, 'course_id': unicode(location.course_key), 'item_id': self.name, 'item_type': u'pb-answer', } submissions = sub_api.get_submissions(target_key, limit=1) try: context['student_input'] = submissions[0]['answer'] except IndexError: context['student_input'] = None else: context['student_input'] = self.student_input html = loader.render_template('templates/html/answer_read_only.html', context) fragment = Fragment(html) fragment.add_css_url(self.runtime.local_resource_url(self, self.css_path)) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/answer_recap.js')) fragment.initialize_js('AnswerRecapBlock') return fragment
def student_view(self, context=None): """ The primary view of the FYPXBlock, shown to students when viewing courses. """ #jid = str(self.scope_ids.user_id) jid = str( self.runtime.service( self, 'user').get_current_user().opt_attrs['edx-platform.username']) self.reg_account(jid) html = self.resource_string("static/html/fyp_new.html") frag = Fragment(html.format(self=self)) #frag.add_css(self.resource_string("static/css/fyp.css")) frag.add_css(self.resource_string("static/css/demo.css")) frag.add_css(self.resource_string("static/css/jquery.convform.css")) frag.add_css_url( "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" ) #frag.add_javascript(self.resource_string("static/js/src/fyp.js")) frag.add_javascript("var jid = '%s@fyp';" % (jid)) frag.add_javascript( self.resource_string("static/js/src/jquery.xmpp.js")) frag.add_javascript( self.resource_string("static/js/src/autosize.min.js")) frag.add_javascript( self.resource_string("static/js/src/jquery.convform.js")) frag.add_javascript(self.resource_string("static/js/src/fyp_new.js")) frag.add_javascript_url( "https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js" ) #frag.add_javascript_url("https://code.jquery.com/jquery-3.4.0.min.js") frag.initialize_js('Chat') return frag
def student_view(self, context): """ Renders parameters to template. """ extension = self._get_extension(self.sourceurl) context = { 'course_key': self.runtime.course_id, 'display_name': self.display_name_with_default_escaped, 'instructions_html': self.instructions, 'sourceUrl': self.sourceurl, 'typeSource': extension, 'poster': self.poster_url, 'content_html': self.content, 'token': retrieve_token(self.user_email, self.annotation_token_secret), '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('videoannotation.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
def student_view(self, context): """ Lab view, displayed to the student """ root = ET.fromstring(self.data) items = {} for child in root: if child.tag == 'doc': child.text = urllib.quote(child.text, '') items[child] = {'tag': child.tag, 'text': child.text} fragment = Fragment() context = { 'items': items, } fragment.add_content(render_template('/templates/html/carousel.html', context)) fragment.add_javascript(load_resource('public/js/jquery-ui-1.10.4.custom.js')) fragment.add_css(load_resource('public/css/responsive-carousel.css')) fragment.add_css(load_resource('public/css/responsive-carousel.slide.css')) fragment.add_javascript(load_resource('public/js/responsive-carousel.js')) fragment.add_css_url("https://vjs.zencdn.net/4.5.1/video-js.css") fragment.add_javascript_url("https://vjs.zencdn.net/4.5.1/video.js") fragment.add_javascript(load_resource('public/js/youtube.js')) fragment.add_javascript('function CarouselBlock(runtime, element) { console.log("ok..."); }') fragment.initialize_js('CarouselBlock') return fragment