def build_fragment( self, fragment_js=None, html_source=None, paths_css=[], paths_js=[], urls_css=[], urls_js=[], ): # pylint: disable=dangerous-default-value, too-many-arguments """ Assemble the HTML, JS, and CSS for an XBlock fragment """ fragment = Fragment(html_source) if fragment_js: fragment.initialize_js(fragment_js) 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) return fragment
def build_fragment( self, rendered_template, initialize_js_func, additional_css=[], additional_js=[], ): # pylint: disable=dangerous-default-value, too-many-arguments """ Creates a fragment for display. """ fragment = Fragment(rendered_template) for item in additional_css: url = self.runtime.local_resource_url(self, item) fragment.add_css_url(url) for item in additional_js: url = self.runtime.local_resource_url(self, item) fragment.add_javascript_url(url) settings = { 'image_path': self.runtime.local_resource_url(self, 'static/images/'), 'is_past_due': self.get_is_past_due() } fragment.initialize_js(initialize_js_func, json_args=settings) 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
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 DoneXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/done.html") frag = Fragment(html) #.format(uid=self.scope_ids.usage_id)) 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/jquery/1.11.1/jquery.min.js") 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/done.css")) grow_left = 1 grow_right = 1 if self.align.lower() == "left": grow_left = 0 if self.align.lower() == "right": grow_right = 0 frag.add_css( ".done_left_spacer {{ flex-grow:{l}; }} .done_right_spacer {{ flex-grow:{r}; }}" .format(r=grow_right, l=grow_left)) frag.add_javascript(self.resource_string("static/js/src/done.js")) frag.initialize_js("DoneXBlock", {'state': self.done}) return frag
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 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 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=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 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)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/vendor/jquery-ui-1.10.4.custom.min.css')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/drag_and_drop_edit.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-ui-1.10.4.custom.min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery.html5-placeholder-shim.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/handlebars-v1.1.2.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/drag_and_drop_edit.js')) fragment.initialize_js('DragAndDropEditBlock') return fragment
def student_view(self, context=None): """ The primary view of the VectorDrawXBlock, shown to students when viewing courses. """ context = context or {} context['self'] = self fragment = Fragment() fragment.add_content( loader.render_template('templates/html/vectordraw.html', context)) fragment.add_css_url( "//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" ) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/vectordraw.css')) # Workbench doesn't have Underscore.js, so add it: if WorkbenchRuntime and isinstance(self.runtime, WorkbenchRuntime): fragment.add_javascript_url( "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" ) fragment.add_javascript_url( "//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.98/jsxgraphcore.js") fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/vectordraw.js')) fragment.initialize_js('VectorDrawXBlock', { "settings": self.settings, "user_state": self.user_state }) return fragment
def student_view(self, context): fragment = Fragment() children_contents = [] context = context or {} context['hide_prev_answer'] = True # For Step Builder, we don't show the users' old answers when they try again context['score_summary'] = self.get_score_summary() 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.")) else: 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_django_template('templates/html/mentoring_with_steps.html', { 'self': self, 'title': self.display_name, 'show_title': self.show_title, 'children_contents': children_contents, }, i18n_service=self.i18n_service)) 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/step_util.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_with_steps.js')) fragment.initialize_js('MentoringWithStepsBlock', { 'show_extended_feedback': self.show_extended_feedback(), }) return fragment
def studio_view(self, context): fragment = Fragment() context = {'fields': [], 'self': self} # Build a list of all the fields that can be edited: for field_name in self.editable_fields: if field_name == "expected_result_positions": continue field = self.fields[field_name] assert field.scope in (Scope.content, Scope.settings), ( "Only Scope.content or Scope.settings fields can be used with " "StudioEditableXBlockMixin. Other scopes are for user-specific data and are " "not generally created/configured by content authors in Studio." ) field_info = self._make_field_info(field_name, field) if field_info is not None: context["fields"].append(field_info) fragment.add_content( loader.render_template("templates/html/vectordraw_edit.html", context)) # Add resources to studio_view fragment fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/vectordraw.css')) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/vectordraw_edit.css')) fragment.add_javascript_url( "//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.98/jsxgraphcore.js") fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/studio_edit.js')) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/vectordraw_edit.js')) fragment.initialize_js('VectorDrawXBlockEdit', {"settings": self.settings}) return fragment
def student_view(self, context): """ Player view, displayed to the student """ max_score_string = '({0} Point{1} Possible)'.format(int(self.weight), 's' if self.weight > 1 else '') if self.weight else '' js_templates = load_resource('/templates/html/js_templates.html') context = { 'js_templates': js_templates, 'title': self.display_name, 'question_text': self.question_text, 'max_score_string': max_score_string } fragment = Fragment() fragment.add_content(render_template('/templates/html/drag_and_drop.html', context)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/vendor/jquery-ui-1.10.4.custom.min.css')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/drag_and_drop.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-ui-1.10.4.custom.min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery.html5-placeholder-shim.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/handlebars-v1.1.2.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/drag_and_drop.js')) fragment.initialize_js('DragAndDropBlock') return fragment
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_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
def student_view(self, context): """ Player view, displayed to the student """ max_score_string = '({0} Point{1} Possible)'.format(int(self.weight), 's' if self.weight > 1 else '') if self.weight else '' js_templates = load_resource('/templates/html/js_templates.html') context = { 'js_templates': js_templates, 'title': self.display_name, 'question_text': self.question_text, 'max_score_string': max_score_string } fragment = Fragment() fragment.add_content(render_template('/templates/html/drag_and_drop.html', context)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/vendor/jquery-ui-1.10.4.custom.min.css')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/drag_and_drop.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-ui-1.10.4.custom.min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery.html5-placeholder-shim.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/handlebars-v1.1.2.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/drag_and_drop.js')) fragment.initialize_js('DragAndDropBlock') 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 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): """ 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 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
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): fragment = Fragment() children_contents = [] context = context or {} context['hide_prev_answer'] = True # For Step Builder, we don't show the users' old answers when they try again context['score_summary'] = self.get_score_summary() 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.")) else: 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_django_template('templates/html/mentoring_with_steps.html', { 'self': self, 'title': self.display_name, 'show_title': self.show_title, 'children_contents': children_contents, }, i18n_service=self.i18n_service)) 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/step_util.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.underscore'), "text/html") fragment.initialize_js('MentoringWithStepsBlock', { 'show_extended_feedback': self.show_extended_feedback(), }) return fragment
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): """ 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 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 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=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 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
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): """ 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 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 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 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 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(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 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 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 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=None): """ The primary view of the VectorDrawXBlock, shown to students when viewing courses. """ context = context or {} context['self'] = self fragment = Fragment() fragment.add_content(loader.render_template('templates/html/vectordraw.html', context)) fragment.add_css_url( "//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" ) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/vectordraw.css')) # Workbench doesn't have Underscore.js, so add it: if WorkbenchRuntime and isinstance(self.runtime, WorkbenchRuntime): fragment.add_javascript_url( "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" ) fragment.add_javascript_url( "//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.98/jsxgraphcore.js" ) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/vectordraw.js') ) fragment.initialize_js( 'VectorDrawXBlock', {"settings": self.settings, "user_state": self.user_state} ) return fragment
def student_view(self, context=None): """The main view of OpenAssessmentBlock, displayed when viewing courses. The main view which displays the general layout for Open Ended Assessment Questions. The contents of the XBlock are determined dynamically based on the assessment workflow configured by the author. Args: context: Not used for this view. Returns: (Fragment): The HTML Fragment for this XBlock, which determines the general frame of the Open Ended Assessment Question. """ # On page load, update the workflow status. # We need to do this here because peers may have graded us, in which # case we may have a score available. try: self.update_workflow_status() except AssessmentWorkflowError: # Log the exception, but continue loading the page logger.exception('An error occurred while updating the workflow on page load.') ui_models = self._create_ui_models() # All data we intend to pass to the front end. context_dict = { "title": self.title, "prompts": self.prompts, "rubric_assessments": ui_models, "show_staff_area": self.is_course_staff and not self.in_studio_preview, } template = get_template("openassessmentblock/oa_base.html") context = Context(context_dict) fragment = Fragment(template.render(context)) i18n_service = self.runtime.service(self, 'i18n') if hasattr(i18n_service, 'get_language_bidi') and i18n_service.get_language_bidi(): css_url = "static/css/openassessment-rtl.css" else: css_url = "static/css/openassessment-ltr.css" if settings.DEBUG: fragment.add_css_url(self.runtime.local_resource_url(self, css_url)) 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/lms") else: # TODO: load CSS and JavaScript as URLs once they can be served by the CDN fragment.add_css(load(css_url)) fragment.add_javascript(load("static/js/openassessment-lms.min.js")) js_context_dict = { "ALLOWED_IMAGE_MIME_TYPES": self.ALLOWED_IMAGE_MIME_TYPES, "ALLOWED_FILE_MIME_TYPES": self.ALLOWED_FILE_MIME_TYPES, "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST, "FILE_TYPE_WHITE_LIST": self.white_listed_file_types, } fragment.initialize_js('OpenAssessmentBlock', js_context_dict) return fragment
def student_view(self, context): """ Player view, displayed to the student """ xmltree = etree.fromstring(self.data) description = self._get_description(xmltree) hotspots = self._get_hotspots(xmltree) background = self._get_background(xmltree) has_youtube = False has_ooyala = False for hotspot in hotspots: width = 'width:{0}px'.format(hotspot.feedback.width) if hotspot.feedback.width else 'width:300px' height = 'height:{0}px'.format(hotspot.feedback.height) if hotspot.feedback.height else '' max_height = '' if not hotspot.feedback.height: max_height = 'max-height:{0}px'.format(hotspot.feedback.max_height) if \ hotspot.feedback.max_height else 'max-height:300px' hotspot.reveal_style = 'style="{0};{1};{2}"'.format(width, height, max_height) if hotspot.feedback.youtube: has_youtube = True if hotspot.feedback.ooyala: has_ooyala = True context = { 'title': self.display_name, 'hotspot_coordinates_centered': self.hotspot_coordinates_centered, 'description_html': description, 'hotspots': hotspots, 'background': background, 'ie_uid': uuid.uuid4().hex[:15], } fragment = Fragment() fragment.add_content( loader.render_django_template( '/templates/html/image_explorer.html', context=context, i18n_service=self.runtime.service(self, 'i18n') ) ) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/image_explorer.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/image_explorer.js')) if has_youtube: fragment.add_javascript_url('https://www.youtube.com/iframe_api') if has_ooyala: fragment.add_javascript_url( '//player.ooyala.com/core/10efd95b66124001b415aa2a4bee29c8?plugins=main,bm' ) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/ooyala_player.js')) fragment.initialize_js('ImageExplorerBlock') return fragment
def student_view(self, context=None): """The main view of OpenAssessmentBlock, displayed when viewing courses. The main view which displays the general layout for Open Ended Assessment Questions. The contents of the XBlock are determined dynamically based on the assessment workflow configured by the author. Args: context: Not used for this view. Returns: (Fragment): The HTML Fragment for this XBlock, which determines the general frame of the Open Ended Assessment Question. """ # On page load, update the workflow status. # We need to do this here because peers may have graded us, in which # case we may have a score available. try: self.update_workflow_status() except AssessmentWorkflowError: # Log the exception, but continue loading the page logger.exception('An error occurred while updating the workflow on page load.') ui_models = self._create_ui_models() # All data we intend to pass to the front end. context_dict = { "title": self.title, "prompts": self.prompts, "rubric_assessments": ui_models, "show_staff_area": self.is_course_staff and not self.in_studio_preview, } template = get_template("openassessmentblock/oa_base.html") context = Context(context_dict) fragment = Fragment(template.render(context)) i18n_service = self.runtime.service(self, 'i18n') if hasattr(i18n_service, 'get_language_bidi') and i18n_service.get_language_bidi(): css_url = "static/css/openassessment-rtl.css" else: css_url = "static/css/openassessment-ltr.css" if settings.DEBUG: fragment.add_css_url(self.runtime.local_resource_url(self, css_url)) 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/lms") else: # TODO: load CSS and JavaScript as URLs once they can be served by the CDN fragment.add_css(load(css_url)) fragment.add_javascript(load("static/js/openassessment-lms.min.js")) js_context_dict = { "ALLOWED_IMAGE_MIME_TYPES": self.ALLOWED_IMAGE_MIME_TYPES, "ALLOWED_FILE_MIME_TYPES": self.ALLOWED_FILE_MIME_TYPES, "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST, "FILE_TYPE_WHITE_LIST": self.white_listed_file_types, } fragment.initialize_js('OpenAssessmentBlock', js_context_dict) return fragment
def student_view(self, context): context['self'] = self fragment = Fragment() fragment.add_content( loader.render_template('templates/html/overlay.html', context)) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/overlay.css')) return fragment
def studio_view(self, context=None): self.logdebug ("studio_view ()") html = self.resource_string("static/html/ctatstudio.html") frag = Fragment(html.format(self=self)) frag.add_javascript_url(self.strip_local(self.runtime.local_resource_url (self,"public/js/ctatstudio.js"))) frag.add_css_url(self.strip_local(self.runtime.local_resource_url (self,"public/css/ctatstudio.css"))) frag.initialize_js('CTATXBlockStudio') return frag
def student_view(self, context=None): """ The primary view of the HastexoXBlock, shown to students when viewing courses. """ # Load configuration settings = get_xblock_settings() # Get the course id and anonymous user id, and derive the stack name # from them course_id, student_id = self.get_block_ids() self.stack_run = "%s_%s" % (course_id.course, course_id.run) self.stack_name = "%s_%s" % (self.stack_run, student_id) frag = Fragment() # Render children child_content = "" for child_id in self.children: child = self.runtime.get_block(child_id) child_fragment = child.render("student_view", context) frag.add_frag_resources(child_fragment) child_content += child_fragment.content # Render the main template frag.add_content(loader.render_django_template( "static/html/main.html", {"child_content": child_content} )) # Add the public CSS and JS frag.add_css_url( self.runtime.local_resource_url(self, 'public/css/main.css') ) frag.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/plugins.js') ) frag.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/main.js') ) # Create the stack in the database stack = self.create_stack(settings, course_id, student_id) # Call the JS initialization function frag.initialize_js('HastexoXBlock', { "terminal_url": settings.get("terminal_url"), "timeouts": settings.get("js_timeouts"), "has_tests": len(self.tests) > 0, "protocol": self.stack_protocol, "ports": self.ports, "port": stack.port, "color_scheme": settings.get("terminal_color_scheme"), "font_name": settings.get("terminal_font_name"), "font_size": settings.get("terminal_font_size"), "instructions_layout": settings.get("instructions_layout") }) return frag
def studio_view(self, context): """ Editing view in Studio """ js_templates = loader.load_unicode('/templates/html/js_templates.html') # Get a 'html_id' 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.location.html_id() # pylint: disable=no-member 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/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/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 student_view(self, context): """ Player view, displayed to the student """ xmltree = etree.fromstring(self.data) description = self._get_description(xmltree) hotspots = self._get_hotspots(xmltree) background = self._get_background(xmltree) has_youtube = False has_ooyala = False for hotspot in hotspots: width = 'width:{0}px'.format(hotspot.feedback.width) if hotspot.feedback.width else 'width:300px' height = 'height:{0}px'.format(hotspot.feedback.height) if hotspot.feedback.height else '' max_height = '' if not hotspot.feedback.height: max_height = 'max-height:{0}px'.format(hotspot.feedback.max_height) if \ hotspot.feedback.max_height else 'max-height:300px' hotspot.reveal_style = 'style="{0};{1};{2}"'.format(width, height, max_height) if hotspot.feedback.youtube: has_youtube = True if hotspot.feedback.ooyala: has_ooyala = True context = { 'title': self.display_name, 'hotspot_coordinates_centered': self.hotspot_coordinates_centered, 'description_html': description, 'hotspots': hotspots, 'background': background, } fragment = Fragment() fragment.add_content( loader.render_django_template( '/templates/html/image_explorer.html', context=context, i18n_service=self.runtime.service(self, 'i18n') ) ) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/image_explorer.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/image_explorer.js')) if has_youtube: fragment.add_javascript_url('https://www.youtube.com/iframe_api') if has_ooyala: fragment.add_javascript_url( 'https://player.ooyala.com/v3/635104fd644c4170ae227af2de27deab?platform=html5-priority' ) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/ooyala_player.js')) fragment.initialize_js('ImageExplorerBlock') return fragment
def _student_view_studio(self): """ Renders student view for Studio """ fragment = Fragment() fragment.add_content(render_mako_template( 'discussion/_discussion_inline_studio.html', {'discussion_id': self.discussion_id} )) fragment.add_css_url(asset_to_static_url('xblock/discussion/css/discussion-studio.css')) return fragment
def queue_view(self, context): result = Fragment() queue = super(QueueWidget, self).student_view(context) result.add_frag_resources(queue) html = self.runtime.render_template("static/html/queue.html", queue=queue) result.add_content(html) result.add_css_url('static/css/stuview.css') return result
def student_view(self, context): context = context.copy() if context else {} fragment = Fragment() for child_id in self.children: child = self.runtime.get_block(child_id) # Child should be an instance of MentoringTableColumn child_frag = child.render('mentoring_view', context) fragment.add_frag_resources(child_frag) context['allow_sharing'] = self.allow_sharing context['allow_download'] = self.allow_download user_service = self.runtime.service(self, 'user') if user_service: context['view_options'] = Share.objects.filter( shared_with__username=self.current_user_key, block_id=self.block_id, ).values_list('shared_by__username', flat=True) context['username'] = self.current_user_key share_notifications = Share.objects.filter( shared_with__username=self.current_user_key, notified=False, block_id=self.block_id, ).values_list('shared_by__username', flat=True) context['share_notifications'] = share_notifications and json.dumps(list(share_notifications)) if self.type: # Load an optional background image: context['bg_image_url'] = self.runtime.local_resource_url(self, 'public/img/{}-bg.png'.format(self.type)) # Load an optional description for the background image, for accessibility try: context['bg_image_description'] = loader.load_unicode('static/text/table-{}.txt'.format(self.type)) except IOError as e: if e.errno == errno.ENOENT: pass else: raise report_template = loader.render_template('templates/html/mentoring-table-report.html', { 'title': self.display_name, 'css': loader.load_unicode(AnswerRecapBlock.css_path) + loader.load_unicode(self.css_path), 'student_name': self._get_user_full_name(), 'course_name': self._get_course_name(), }) fragment.add_content(loader.render_template('templates/html/mentoring-table-container.html', context)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mentoring-table.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-shorten.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, self.js_path)) fragment.initialize_js( 'MentoringTableBlock', { 'reportContentSelector': '.mentoring-table-container', 'reportTemplate': report_template, } ) return fragment
def student_view(self, context): context = context.copy() if context else {} fragment = Fragment() for child_id in self.children: child = self.runtime.get_block(child_id) # Child should be an instance of MentoringTableColumn child_frag = child.render('mentoring_view', context) fragment.add_frag_resources(child_frag) context['allow_sharing'] = self.allow_sharing context['allow_download'] = self.allow_download user_service = self.runtime.service(self, 'user') if user_service: context['view_options'] = Share.objects.filter( shared_with__username=self.current_user_key, block_id=self.block_id, ).values_list('shared_by__username', flat=True) context['username'] = self.current_user_key share_notifications = Share.objects.filter( shared_with__username=self.current_user_key, notified=False, block_id=self.block_id, ).values_list('shared_by__username', flat=True) context['share_notifications'] = share_notifications and json.dumps(list(share_notifications)) if self.type: # Load an optional background image: context['bg_image_url'] = self.runtime.local_resource_url(self, 'public/img/{}-bg.png'.format(self.type)) # Load an optional description for the background image, for accessibility try: context['bg_image_description'] = loader.load_unicode('static/text/table-{}.txt'.format(self.type)) except IOError as e: if e.errno == errno.ENOENT: pass else: raise report_template = loader.render_template('templates/html/mentoring-table-report.html', { 'title': self.display_name, 'css': loader.load_unicode(AnswerRecapBlock.css_path) + loader.load_unicode(self.css_path), 'student_name': self._get_user_full_name(), 'course_name': self._get_course_name(), }) fragment.add_content(loader.render_template('templates/html/mentoring-table-container.html', context)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mentoring-table.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-shorten.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, self.js_path)) fragment.initialize_js( 'MentoringTableBlock', { 'reportContentSelector': '.mentoring-table-container', 'reportTemplate': report_template, } ) return fragment
def mentoring_table_view(self, context=None): html = loader.custom_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
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
def student_view(self, context=None): """ Student View """ context = context.copy() if context else {} context['hide_header'] = True context['self'] = self fragment = Fragment() fragment.add_content(loader.render_template('templates/html/plot.html', context)) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/plot.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/d3.min.js')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/plot.js')) fragment.initialize_js('PlotBlock') return fragment
def student_view(self, context): html = render_template('templates/html/dataexport.html', { 'self': self, }) fragment = Fragment(html) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/dataexport.js')) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/dataexport.css')) fragment.initialize_js('MentoringDataExportBlock') return fragment
def mentoring_view(self, context=None): """ Render this XBlock within a mentoring block. """ context = context.copy() if context else {} context['self'] = self context['hide_header'] = context.get('hide_header', False) or not self.show_title html = loader.render_template('templates/html/answer_editable.html', context) fragment = Fragment(html) fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/answer.css')) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/answer.js')) fragment.initialize_js('AnswerBlock') return fragment
def student_view(self, context=None): """ The primary view of the SchoolYourselfReviewXBlock, shown to students when viewing courses. """ # Construct the URL we're going to stuff into the iframe once # it gets launched: partner_url_params = self.get_partner_url_params(self.shared_key) iframe_url_params = dict(partner_url_params) iframe_url_params["module"] = self.module_id mastery_url_params = dict(partner_url_params) mastery_url_params["tags"] = self.module_id # Set up the screenshot URL: screenshot_url = "%s/page/screenshot/%s" % (self.base_url, self.module_id) mastery_url = "%s/progress/mastery?%s" % ( self.base_url, urllib.urlencode(mastery_url_params)) context = { "iframe_url": "%s/review/embed?%s" % ( self.base_url, urllib.urlencode(iframe_url_params)), "title": self.module_title, "icon_url": self.runtime.local_resource_url(self, "public/review_icon.png"), "mastery_url": mastery_url } # Now actually render the fragment, which is just a button with # some JS code that handles the click event on that button. fragment = Fragment(self.render_template("review_student_view.html", context)) # Load the common JS/CSS libraries: fragment.add_css_url( self.runtime.local_resource_url(self, "public/sylib.css")) fragment.add_javascript_url( self.runtime.local_resource_url(self, "public/sylib.js")) # And finally the embedded HTML/JS code: fragment.add_javascript(self.resource_string( "static/js/review_student_view.js")) fragment.add_css(self.resource_string( "static/css/student_view.css")) fragment.add_css_url("//fonts.googleapis.com/css?family=Open+Sans:700,400,300") fragment.initialize_js("SchoolYourselfReviewStudentView") return fragment