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_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 XBlock, shown to students when viewing courses. """ fullUrl = self.url if self.start_time != "" and self.end_time != "": fullUrl += "#t=" + self.start_time + "," + self.end_time elif self.start_time != "": fullUrl += "#t=" + self.start_time elif self.end_time != "": fullUrl += "#t=0," + self.end_time context = { "display_name": self.display_name, "url": fullUrl, "allow_download": self.allow_download, "source_text": self.source_text, "source_url": self.source_url, } html = self.render_template("static/html/videojs_view.html", context) frag = Fragment(html) frag.add_css(self.load_resource("static/css/video-js.min.css")) frag.add_css(self.load_resource("static/css/videojs.css")) frag.add_javascript(self.load_resource("static/js/video-js.js")) frag.add_javascript(self.load_resource("static/js/videojs_view.js")) frag.initialize_js("videojsXBlockInitView") return frag
def studio_view(self, context=None): """ view function for studio edit """ html = self.resource_string("static/html/ubcpi_edit.html") frag = Fragment(html) frag.add_javascript(self.resource_string("static/js/src/ubcpi_edit.js")) frag.initialize_js('PIEdit', { 'display_name': self.ugettext(self.display_name), 'weight': self.weight, 'correct_answer': self.correct_answer, 'correct_rationale': self.correct_rationale, 'rationale_size': self.rationale_size, 'question_text': self.question_text, 'options': self.options, 'algo': self.algo, 'algos': { 'simple': self.ugettext('System will select one of each option to present to the students.'), 'random': self.ugettext('Completely random selection from the response pool.') }, 'image_position_locations': { 'above': self.ugettext('Appears above'), 'below': self.ugettext('Appears below') }, 'seeds': self.seeds, }) 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 SqlInjectionXBlock, shown to students when viewing courses. """ if self.problem_id not in self.AVAILABLE_PROBLEMS: frag = Fragment(u"problem_id {} is not valid".format(self.problem_id)) return frag problem_resources = self.AVAILABLE_PROBLEMS[self.problem_id] html = self.resource_string(problem_resources['html']) frag = Fragment(html.format(self=self)) for css_file in problem_resources['css']: frag.add_css(self.resource_string(css_file)) for js_file in problem_resources['js']: js_str = Template(self.resource_string(js_file)).render( Context({ 'prev_answers_json': json.dumps(getattr(self, problem_resources['log'])), 'problem_score': self.student_score, 'problem_weight': self.weight, 'attempts': self.student_attempts, })) frag.add_javascript(js_str) for js_obj in problem_resources['js_objs']: frag.initialize_js(js_obj) return frag
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 studio_view(self, context=None): """This is the view displaying xblock form in studio.""" logger.debug("On entre dans la partie prof") # logger.debug("self.max_id_question : %s", self.max_id_question) # logger.debug("self.dict_questions : %s", self.dict_questions) # logger.debug("self.max_id_studio_question : %s", self.max_id_studio_question) # logger.debug("self.dict_studio_questions : %s", self.dict_studio_questions) logger.debug(" self.var_test : %s", self.var_test) # q = "Que permet de faire le théorème de Bayes ? Donner un exemple ?" # r = "Il permet d'inverser des probabilités pourvu qu'on ait des connaissances préalables." # r_etu = "Si l'on connait P(A), P(B) et P(A|B),le théorème de Bayes nous permet de calculer P(B|A)." # for i in range(5): # self.add_studio_question(q, r) # logger.debug("self.max_id_question : %s", self.max_id_question) # logger.debug("self.dict_questions : %s", self.dict_questions) # logger.debug("self.max_id_studio_question : %s", self.max_id_studio_question) # logger.debug("self.dict_studio_questions : %s", self.dict_studio_questions) # logger.debug("self.var_test : %s", self.var_test) logger.debug("On sort de la partie prof") # self.t_prof_last_modif = time() frag = Fragment(self.resource_string("templates/studio.html")) frag.add_javascript(self.resource_string("static/js/src/p3exblock_studio.js")) frag.initialize_js('P3eXBlock') return frag
def studio_view(self, context=None): fragment = Fragment() fragment.add_content(Util.render_template("static/html/uc_rtc_studio.html")) fragment.add_css(Util.load_resource("static/css/uc_rtc.css")) fragment.add_javascript(Util.load_resource("static/js/src/uc_rtc_edit.js")) fragment.initialize_js("UcRtcXBlock") 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 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 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 XBlock, shown to students when viewing courses. ''' problem_progress = self._get_problem_progress() used_attempts_feedback = self._get_used_attempts_feedback() submit_class = self._get_submit_class() prompt = self._get_body(self.question_string) explanation = self._get_explanation(self.question_string) attributes = '' html = self.resource_string('static/html/submit_and_compare_view.html') frag = Fragment( html.format( display_name=self.display_name, problem_progress=problem_progress, used_attempts_feedback=used_attempts_feedback, submit_class=submit_class, prompt=prompt, student_answer=self.student_answer, explanation=explanation, your_answer_label=self.your_answer_label, our_answer_label=self.our_answer_label, submit_button_label=self.submit_button_label, attributes=attributes, ) ) frag.add_css(self.resource_string('static/css/submit_and_compare.css')) frag.add_javascript( self.resource_string('static/js/submit_and_compare_view.js'), ) frag.initialize_js('SubmitAndCompareXBlockInitView') return frag
def studio_view(self, context): """ Отображение блока в студии. :param context: :return: """ template_context = { 'metadata': json.dumps({ 'display_name': self.display_name, 'course_id': self.ant_course_id, 'unit_id': self.ant_unit_id, 'content': self.content, 'time_limit': self.ant_time_limit, 'attempts_limit': self.ant_attempts_limit, 'attempts_url': self.attempts_url, 'lab_url': self.lab_url, 'weight': self.weight, }), } fragment = Fragment() fragment.add_content(self._render_template('static/templates/studio_view.html', template_context)) fragment.add_javascript(self._get_resource('static/js/studio_view.js')) fragment.initialize_js('AntXBlockEdit') return fragment
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=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(_resource("static/js/src/jquery.tablesorter.min.js")) fragment.initialize_js('StaffGradedAssignmentXBlock') 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, dummy_context=None): """ Create a Fragment used to display a CTAT StatTutor xBlock to a student. Returns a Fragment object containing the HTML to display """ # read in template html html = self.resource_string("static/html/ctatxblock.html") frag = Fragment(html.format( tutor_html=self.get_local_resource_url(self.src))) config = self.resource_string("static/js/CTATConfig.js") frag.add_javascript(config.format( self=self, tutor_html=self.get_local_resource_url(self.src), question_file=self.get_local_resource_url(self.brd), student_id=self.runtime.anonymous_student_id if hasattr(self.runtime, 'anonymous_student_id') else 'bogus-sdk-id', problem_description=self.get_local_resource_url( self.problem_description), guid=str(uuid.uuid4()))) frag.add_javascript(self.resource_string( "static/js/Initialize_CTATXBlock.js")) frag.initialize_js('Initialize_CTATXBlock') return frag
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): """ 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=None): """ The primary view of the TableXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/table.html") frag = Fragment(html.format(self=self)) frag.add_css(self.resource_string("static/css/table.css")) frag.add_javascript(self.resource_string("static/js/lib/xapiwrapper.min.js")) frag.add_javascript(self.resource_string("static/js/lib/knockout-3.1.0.js")) frag.add_javascript(self.resource_string("static/js/lib/knockout.mapping-latest.debug.js")) randNum = str(randint(0, 10000)) js = self.resource_string("static/js/src/table.js") tab = self.s_tableStructure showColumns = self.s_showColumns userRows = self.userRows jsStr = js.replace('{{tableStructure}}', tab) jsStr = jsStr.replace('{{showColumns}}', showColumns) jsStr = jsStr.replace('{{userRows}}', json.dumps(userRows)) jsStr = jsStr.replace('{{display_name}}', self.display_name) jsStr = jsStr.replace('{{randFuncName}}', randNum) jsStr = jsStr.replace('{{currentStructure}}', self.currentStructure) frag.add_javascript(jsStr) frag.initialize_js('TableXBlock' + randNum) return frag
def student_view(self, context=None): """ The primary view of the LaunchContainerXBlock, shown to students when viewing courses. """ user_email = None # workbench runtime won't supply system property if getattr(self, 'system', None): if self.system.anonymous_student_id: if getattr(self.system, 'get_real_user', None): anon_id = self.system.anonymous_student_id user = self.system.get_real_user(anon_id) if user and user.is_authenticated(): user_email = user.email elif self.system.user_is_staff: # Studio preview from django.contrib.auth.models import User user = User.objects.get(id=self.system.user_id) user_email = user.email context = { 'project': self.project, 'project_friendly': self.project_friendly, 'user_email' : user_email, 'API_url': self.api_url } frag = Fragment() frag.add_content( render_template('static/html/launchcontainer.html', context) ) frag.add_javascript(render_template("static/js/src/launchcontainer.js", context)) frag.initialize_js('LaunchContainerXBlock') return frag
def student_view(self, context=None): """ The primary view of the SharedFieldDemoXBlock, shown to students when viewing courses. """ # get the shared field data value # user_id ("2") is hard-coded self.user_id = self.scope_ids.user_id self.shared_num_query_value = self.shared_num_query.get(xblock=self, field_name = 'count', user_id='3') self.verifed_query_value = self.verifed_query.get( xblock=self, field_name = 'verified', user_id = 'student_1', usage_id = 'toyverifyxblock.toy_verify.d0.u0') if self.verifed_query_value: self.html_text = "You need to verify before the exam" else: self.html_text = "Wonderful! Here is your exam content" html = self.resource_string("static/html/shared_field_demo.html") frag = Fragment(html.format(self=self)) frag.add_css(self.resource_string("static/css/shared_field_demo.css")) frag.add_javascript(self.resource_string("static/js/src/shared_field_demo.js")) frag.initialize_js('SharedFieldDemoXBlock') return frag
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): """ The primary view of the GenexerciseXBlock, shown to students when viewing courses. """ """ pull answer files from gitlab """ # os.system('/var/www/zyni/script/pullFromGitlab.sh') """ statistic according to answer files """ # os.system('python /var/www/zyni/script/statistic.py') """ push result to github """ # os.system('/var/www/zyni/script/pushToGitHubStatistic.sh') html = self.resource_string("static/html/genexercise.html") frag = Fragment(html.format(self=self)) frag.add_css(self.resource_string("static/css/genexercise.css")) frag.add_javascript(self.resource_string("static/js/src/genexercise.js")) frag.initialize_js('GenexerciseXBlock') return frag
def student_view(self, context=None): """ The primary view of the StaffGradedAssignmentXBlock, 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: self.runtime.publish(self, 'grade', { 'value': self.score, 'max_value': self.max_score(), }) self.score_published = True template = get_template("staff_graded_assignment/show.html") context = { "student_state": json.dumps(self.student_state()), "id": "_".join(filter(None, self.location)) } if self.show_staff_grading_interface(): context['is_course_staff'] = True fragment = Fragment(template.render(Context(context))) fragment.add_css(_resource("static/css/edx_sga.css")) fragment.add_javascript(_resource("static/js/src/edx_sga.js")) fragment.initialize_js('StaffGradedAssignmentXBlock') 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 studio_view(self, context=None): # pylint: disable=unused-argument """ Render the OpenAssessment XBlock for editing in Studio. Args: context: Not actively used for this view. Returns: (Fragment): An HTML fragment for editing the configuration of this XBlock. """ rendered_template = get_template( 'openassessmentblock/edit/oa_edit.html' ).render(self.editor_context()) fragment = Fragment(rendered_template) if settings.DEBUG: self.add_javascript_files(fragment, "static/js/src/oa_shared.js") self.add_javascript_files(fragment, "static/js/src/oa_server.js") self.add_javascript_files(fragment, "static/js/src/studio") else: # TODO: switch to add_javascript_url once XBlock resources are loaded from the CDN fragment.add_javascript(pkg_resources.resource_string(__name__, "static/js/openassessment-studio.min.js")) js_context_dict = { "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST, } fragment.initialize_js('OpenAssessmentEditor', js_context_dict) return fragment
def studio_view(self, context=None): ''' The secondary view of the XBlock, shown to teachers when editing the XBlock. ''' context = { 'display_name': self.display_name, 'weight': self.weight, 'max_attempts': self.max_attempts, 'xml_data': self.question_string, 'your_answer_label': self.your_answer_label, 'our_answer_label': self.our_answer_label, 'submit_button_label': self.submit_button_label, } html = self.render_template( 'static/html/submit_and_compare_edit.html', context, ) frag = Fragment(html) frag.add_javascript( self.load_resource('static/js/submit_and_compare_edit.js'), ) frag.initialize_js('SubmitAndCompareXBlockInitEdit') return frag
def load_view(self, filename, data=[]): """Loading the whole XBlock fragment""" frag = Fragment(self.render_template(filename, data)) frag.add_css(self.resource_string("static/css/p3exblock.css")) frag.add_javascript(self.resource_string("static/js/src/p3exblock.js")) frag.initialize_js('P3eXBlock') return frag
def studio_view(self, context): """ Editing view in Studio """ fragment = Fragment() fragment.add_content( loader.render_template('templates/html/mentoring_edit.html', { 'self': self, 'xml_content': self.xml_content, })) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/mentoring_edit.js')) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/mentoring_edit.css')) fragment.initialize_js('MentoringEditBlock') return fragment
def studio_view(self, context=None): """This is the view displaying xblock form in studio.""" api_obj = ProctoruAPI() timezones = api_obj.get_time_zones() time_zone_list = timezones.get("data") fragment = Fragment() fragment.add_content( loader.render_template('static/html/studio_edit.html', { 'time_zone_list': time_zone_list, 'self': self })) fragment.add_css( self.resource_string('public/css/custom_bootstrap.css')) fragment.add_css(self.resource_string('public/css/proctoru.css')) fragment.add_javascript( self.resource_string("static/js/src/studio_edit.js")) fragment.initialize_js('ProctoruStudio') return fragment
def student_view(self, context=None): """ The primary view of the SortableXBlock, shown to students when viewing courses. """ frag = Fragment() items = self.data[:] if not self.completed: random.shuffle(items) frag.add_content( loader.render_django_template('static/html/sortable.html', context=dict(items=items, self=self), i18n_service=self.i18n_service)) frag.add_css(self.resource_string("static/css/sortable.css")) frag.add_javascript( self.resource_string("static/js/vendor/sortable.min.js")) frag.add_javascript(self.resource_string("static/js/src/sortable.js")) frag.initialize_js('SortableXBlock') return frag
def studio_view(self, context): # pylint: disable=unused-argument """ Editing view in Studio """ fragment = Fragment() # Need to access protected members of fields to get their default value default_name = self.fields['display_name']._default # pylint: disable=protected-access,unsubscriptable-object fragment.add_content( RESOURCE_LOADER.render_template(DOCUMENT_EDIT_TEMPLATE, { 'self': self, 'defaultName': default_name, })) fragment.add_javascript( RESOURCE_LOADER.load_unicode('public/js/google_docs_edit.js')) fragment.add_css( RESOURCE_LOADER.load_unicode('public/css/google_edit.css')) fragment.initialize_js('GoogleDocumentEditBlock') return fragment
def student_view(self, context): # pylint: disable=unused-argument """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content( RESOURCE_LOADER.render_django_template( DOCUMENT_TEMPLATE, context={"self": self}, i18n_service=self.runtime.service(self, 'i18n'), )) fragment.add_css( RESOURCE_LOADER.load_unicode('public/css/google_docs.css')) fragment.add_javascript( RESOURCE_LOADER.load_unicode('public/js/google_docs.js')) fragment.initialize_js('GoogleDocumentBlock') return fragment
def studio_view(self, context=None): """ The secondary view of the XBlock, shown to teachers when editing the XBlock. """ context = { 'display_name': self.display_name, 'url': self.url, 'allow_download': self.allow_download, 'source_text': self.source_text, 'source_url': self.source_url, 'display_description': self.display_description, 'document_type_doc': self.document_type == 'doc' } html = self.render_template('static/html/pdf_edit.html', context) frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_edit.js")) frag.initialize_js('pdfXBlockInitEdit') return frag
def student_view(self, context=None): """ The primary view shown to students when viewing courses. """ context = { "student_state": json.dumps(self.student_state()), "id": self.location.name.replace('.', '_'), } fragment = Fragment() fragment.add_content( render_template('templates/assignment/chessgridxblock.html', context)) fragment.add_css(_resource("static/css/chessgridxblock.css")) fragment.add_javascript(_resource("static/js/src/chessgridxblock.js")) fragment.initialize_js('ChessgridXBlock') js_str = pkg_resources.resource_string( __name__, "static/js/src/grid_library.js") fragment.add_javascript(unicode(js_str)) return fragment
def student_view(self, context=None): """ The primary view of the XBlock, shown to students when viewing courses. """ context = { 'display_name': self.display_name, 'url': self.url, 'allow_download': self.allow_download, 'source_text': self.source_text, 'source_url': self.source_url } html = self.render_template('static/html/pdf_view.html', context) frag = Fragment(html) frag.add_css(self.load_resource("static/css/pdf.css")) frag.add_javascript(self.load_resource("static/js/pdf_view.js")) frag.initialize_js('pdfXBlockInitView') return frag
def student_view(self, context=None): """ View shown to students. """ context = self.student_view_data(context=context) context.update(self._get_user_state()) fragment = Fragment() fragment.add_content( loader.render_django_template('templates/eoc_journal.html', context=context, i18n_service=self.i18n_service)) fragment.add_css_url( self.runtime.local_resource_url(self, "public/css/eoc_journal.css")) fragment.add_javascript(self.get_translation_content()) fragment.add_javascript_url( self.runtime.local_resource_url(self, "public/js/eoc_journal.js")) fragment.initialize_js("EOCJournalXBlock") return fragment
def studio_view(self, context): """ Create a fragment used to display the edit view in the Studio. """ context['host_id'] = self.host_id or '' context['meeting_number'] = self.meeting_number or '' context['from_date'] = self.from_date or '' context['to_date'] = self.to_date or '' context['page_size'] = self.page_size context['page_number'] = self.page_number fragment = Fragment() fragment.add_content( render_template('static/html/zoomcloudrecording_edit.html', context)) fragment.add_javascript( load_resource("static/js/src/zoomcloudrecording_edit.js")) fragment.initialize_js('ZoomCloudRecordingEditBlock') 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. """ js_url = 'https://raw.githubusercontent.com/DANCEcollaborative/collab-xblock/master/xblock-dance-discussion/static/js/discussion_dance.js' css_url = 'https://raw.githubusercontent.com/DANCEcollaborative/collab-xblock/master/xblock-dance-discussion/static/css/discussion_dance.css' html_url = 'https://raw.githubusercontent.com/DANCEcollaborative/collab-xblock/master/xblock-dance-discussion/static/html/student_view.html' self.setup_db() html = self.remote_resource_string(html_url) frag = Fragment(unicode(html).format(self=self, comment=self.comment)) css = self.remote_resource_string(css_url) frag.add_css(unicode(css)) js = self.remote_resource_string(js_url) frag.add_javascript(unicode(js)) frag.initialize_js('discussion_dance') return frag
def studio_view(self, context=None): """ The secondary view of the XBlock, shown to teachers when editing the XBlock. """ if self.min_height == '': self.min_height = "450" context = { 'display_name': self.display_name, 'url': self.url, 'new_window_button': self.new_window_button, 'min_height': self.min_height, } html = self.render_template('static/html/embedurl_edit.html', context) frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/embedurl_edit.js")) frag.initialize_js('embedurlXBlockInitEdit') 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() 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): """ Отображение блока в LMS. :param context: :return: """ template_context = self._get_student_context() fragment = Fragment() fragment.add_content( self._render_template('static/templates/student_view.html', template_context)) fragment.add_javascript( self._get_resource('static/js/student_view.js')) fragment.add_css( self._get_resource('static/css/student_view_style.css')) fragment.initialize_js('AntXBlockShow') return fragment
def student_view(self, context=None): """ The primary view of the OfficeVideoXBlock, shown to students when viewing courses. """ embed_code = self.output_code if embed_code == '': embed_code = self.get_officevideo_embed_code( officevideo_url=self.video_url) html = self.resource_string("static/html/officevideo.html") frag = Fragment( html.format(embed_code=embed_code, message=self.message, message_display_state=self.message_display_state)) frag.add_css(self.resource_string("static/css/officevideo.css")) frag.add_javascript( self.resource_string("static/js/src/officevideo.js")) frag.initialize_js('OfficeVideoXBlock') return frag
def create_fragment(self, context, template, css, js, js_init): frag = Fragment() frag.add_content( self.loader.render_django_template( template, context=context, i18n_service=self.i18n_service, )) frag.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/vendor/handlebars.js')) frag.add_css(self.resource_string(css)) frag.add_javascript(self.get_translation_content()) frag.add_javascript(self.resource_string('public/js/poll_common.js')) frag.add_javascript(self.resource_string(js)) frag.initialize_js(js_init) self.include_theme_files(frag) return frag
def student_view(self, context=None): """ The primary view of the TogetherJsXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/cpsxblock.html") frag = Fragment(html.format(self=self)) frag.add_css(self.resource_string("static/css/cpsxblock.css")) frag.add_javascript(self.resource_string("static/js/src/cpsxblock.js")) frag.add_javascript( self.resource_string("static/js/togetherjs-min.js")) frag.initialize_js( 'CPSXBlock', { 'collab_type': self.Collaboration_Type, 'shareable_hints': self.Shareable_Hint_Block_Code, 'shared_blocks': self.theme_shared_content, 'unique_blocks': self.theme_unique_content }) return frag
def student_view(self, context=None): ''' The primary view of the XBlock, shown to students when viewing courses. ''' problem_progress = self._get_problem_progress() prompt = self._get_body(self.question_string) attributes = '' html = self.resource_string('static/html/inline_dropdown_view.html') frag = Fragment( html.format(display_name=self.display_name, problem_progress=problem_progress, prompt=prompt, attributes=attributes)) frag.add_css(self.resource_string('static/css/inline_dropdown.css')) frag.add_javascript( self.resource_string('static/js/inline_dropdown_view.js')) frag.initialize_js('InlineDropdownXBlockInitView') return frag
def staff_view(self): """Display the form for uploading the assessement file.""" spinner_url = self.runtime.local_resource_url( self, 'public/static/images/spinner.gif') frag = Fragment( loader.render_template( "templates/edx_gea/staff.html", { 'upload_assessment_file_form': UploadAssessmentFileForm( auto_id=True, initial={'csv_delimiter': get_default_delimiter()}), 'spinner_url': spinner_url, 'max_assessment_file_lines': self.max_assessment_file_lines })) frag.add_css(loader.load_unicode("static/css/gea.css")) frag.add_javascript(loader.load_unicode("static/js/src/gea.js")) frag.initialize_js('GeaXBlock') return frag
def studio_view(self, context=None): """ The secondary view of the XBlock, shown to teachers when editing the XBlock. """ context = { 'display_name': self.display_name, 'url': self.url, 'allow_download': self.allow_download, 'source_text': self.source_text, 'source_url': self.source_url, 'start_time': self.start_time, 'end_time': self.end_time } html = self.render_template('static/html/videojs_edit.html', context) frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/videojs_edit.js")) frag.initialize_js('videojsXBlockInitStudio') return frag
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.resource_string(item) fragment.add_css(url) for item in additional_js: url = self.resource_string(item) fragment.add_javascript(url) fragment.initialize_js(initialize_js_func) return fragment
def studio_view(self, context): """ Editing view in Studio """ frag = Fragment() context = { 'self': self, 'fields': self.fields, 'data': self.data, } frag.add_content( loader.render_django_template('static/html/sortable_edit.html', context=context, i18n_service=self.i18n_service)) frag.add_css(self.resource_string("static/css/sortable_edit.css")) frag.add_javascript( self.resource_string("static/js/src/sortable_edit.js")) frag.initialize_js('SortableXBlockEdit') return frag
def student_view(self, context=None): """ The primary view of the TestXBlock, shown to students when viewing courses. """ #html = self.resource_string("static/html/testxblock.html") html = self.resource_string("static/html/index.html") frag = Fragment(html.format(self=self)) #frag.add_css(self.resource_string("static/css/testxblock.css")) frag.add_javascript(self.resource_string("static/js/src/testxblock.js")) #frag.initialize_js('TestXBlock') frag.add_css(self.resource_string("static/css/style.css")) frag.add_javascript(self.resource_string("static/js/src/jquery-1.11.0.js")) frag.add_javascript(self.resource_string("static/js/src/popcorn.js")) #frag.add_javascript(self.resource_string("static/js/src/test.js")) frag.initialize_js('TestXBlock') return frag
def studio_view(self, *args, **kwargs): context = { "display_name": self.display_name, "video_id": self.video_id, "video_url": self.video_url, } fragment = Fragment() fragment.add_content( render_template( 'static/html/le_player_edit.html', context ) ) js_urls = ( "static/js/le_player_edit.js", ) self.load_resources(js_urls, fragment) fragment.initialize_js('LePlayerXBlockEdit')
def student_view(self, context=None): """ The primary view of the InfoSecureXBlock, shown to students when viewing courses. """ context = { "display_name": self.display_name, "task_text": self.task_text, "weight": self.weight, "max_attempts": self.max_attempts, "attempts": self.attempts, "points": self.points, } if answer_opportunity(self): context["answer_opportunity"] = True fragment = Fragment() fragment.add_content( render_template( "static/html/infosecurexblock.html", context ) ) js_urls = ( "static/js/src/infosecurexblock.js", # "static/js/src/main.js", ) css_context = dict( comp_icon=self.runtime.local_resource_url(self, "public/images/comp.svg"), transfer_icon=self.runtime.local_resource_url(self, "public/images/transfer.svg"), monitor_icon=self.runtime.local_resource_url(self, "public/images/monitor.svg"), server_3_icon=self.runtime.local_resource_url(self, "public/images/server-3.svg"), file_icon=self.runtime.local_resource_url(self, "public/images/file.svg"), wifi_icon=self.runtime.local_resource_url(self, "public/images/wifi.svg"), ) css_urls = ("static/css/infosecurexblock.css",) # css_context load_resources(js_urls, css_urls, fragment) fragment.initialize_js('InfoSecureXBlock') return fragment
def student_view(self, context): """ Player view, displayed to the student """ xmltree = etree.fromstring(self.data) # parse out all of the XML into nice friendly objects description = self._get_description(xmltree) correct_feedback = self._get_correct_feedback(xmltree) items = self._get_items(xmltree) targets = self._get_targets(xmltree) draggable_target_class = 'draggable-target' if len( targets) > 1 else 'draggable-target-full-width' max_score_string = '({0} Point{1})'.format( int(self.weight), 's' if self.weight > 1 else '') if self.weight else '' context = { 'title': self.display_name, 'description': description, 'items': items, 'targets': targets, 'correct_feedback': correct_feedback, 'draggable_target_class': draggable_target_class, 'max_score_string': max_score_string } fragment = Fragment() fragment.add_content( render_template('/templates/html/drag_and_drop.html', context)) fragment.add_css(load_resource('public/css/drag_and_drop.css')) fragment.add_javascript( load_resource('public/js/vendor/jquery-ui-1.10.4.custom.js')) fragment.add_javascript(load_resource('public/js/drag_and_drop.js')) fragment.initialize_js('DragAndDropBlock') return fragment
def student_view(self, context=None): """ The primary view of the ShortAnswerXBlock, shown to students when viewing courses. """ js_options = { 'gradesPublished': self.grades_published, 'weight': self.weight, 'passedDue': self.passed_due, 'score': self.student_grade, } context.update({ 'answer': self.answer, 'description': self.description, 'feedback': self.feedback, 'grades_published': self.grades_published, 'is_course_staff': getattr(self.xmodule_runtime, 'user_is_staff', False), 'max_score': self.max_score(), 'module_id': self.module. id, # Use the module id to generate different pop-up modals 'passed_due': self.passed_due, 'score': self.student_grade, 'width': self.width, }) frag = Fragment() frag.add_content( render_template('static/html/short_answer.html', context)) frag.add_css(resource_string('static/css/short_answer.css')) frag.add_javascript(resource_string('static/js/src/short_answer.js')) frag.initialize_js('ShortAnswerXBlock', js_options) return frag
def create_fragment(self, html, context={}, js=[], css=[], initialize=None): """ Create an XBlock Fragment Creates an XBlock Fragment given an HTML file path, an optional Context, optional JS file paths, optional CSS file paths, and an optional Initialize JS value Arguments: html (str): HTML File Path context (dict): Optional Context for HTML File js (list): Optional List of JS File Paths css (list): Optional List of CSS File Paths initialize (str): Optional Initialize Value for JS Returns: Fragment """ if isPython27(): html_str = self.load_resource(html) else: html_str = self.resource_string(html) html = Template(html_str) frag = Fragment(html.render(Context(context))) for stylesheet in css: frag.add_css(self.resource_string(stylesheet)) for script in js: frag.add_javascript(self.resource_string(script)) if initialize: frag.initialize_js(initialize) return frag
def student_view(self, context=None): """ Normal View """ if not self.user_is_staff(): return Fragment( u'<p>This interface can only be used by course staff.</p>') block_choices = { self._('Multiple Choice Question'): 'MCQBlock', self._('Multiple Response Question'): 'MRQBlock', self._('Rating Question'): 'RatingBlock', self._('Long Answer'): 'AnswerBlock', } html = loader.render_django_template( 'templates/html/instructor_tool.html', { 'block_choices': block_choices, 'course_blocks_api': COURSE_BLOCKS_API, 'root_block_id': six.text_type(getattr(self.runtime, 'course_id', 'course_id')), }, i18n_service=self.i18n_service) fragment = Fragment(html) fragment.add_javascript(self.get_translation_content()) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/instructor_tool.css')) fragment.add_javascript_url( self.runtime.local_resource_url(self, 'public/js/instructor_tool.js')) 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/vendor/backbone-min.js')) fragment.add_javascript_url( self.runtime.local_resource_url( self, 'public/js/vendor/backbone.paginator.min.js')) fragment.initialize_js('InstructorToolBlock') return fragment
def aside_view(self, block, context=None): """ This view is used by the Acid Aside to test various features of the runtime it is contained in """ scopes = (scope for scope in Scope.scopes() if scope.name in self.enabled_fields['student_view']) scope_test_contexts = [] for scope in scopes: try: scope_test_contexts.append(self.setup_storage(scope.name)) except Exception: logging.warning('Unable to use scope in acid test', exc_info=True) frag = Fragment( self.render_template( 'html/aside.html.mako', usage_id=block.scope_ids.usage_id, error_class=self.ERROR_CLASS, success_class=self.SUCCESS_CLASS, failure_class=self.FAILURE_CLASS, unknown_class=self.UNKNOWN_CLASS, storage_tests=scope_test_contexts, local_resource_url=self.runtime.local_resource_url( self, 'public/test_data.json'), )) frag.add_javascript( self.resource_string("static/js/jquery.ajaxq-0.0.1.js")) frag.add_javascript( self.resource_string('static/js/acid_update_status.js')) frag.add_javascript(self.resource_string('static/js/acid.js')) frag.add_css(self.resource_string("static/css/acid.css")) frag.add_css_url( '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css' ) frag.initialize_js('AcidAsideBlock', {'test_aside': isinstance(block, AcidBlock)}) return frag