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 student_view(self, context=None): """ The primary view of the DjangoBBXBlock, shown to students when viewing courses. """ #html = self.resource_string("static/html/xdjangobb.html") response = requests.get(self.service_url + self.html_service_endpoint_extension) #html = str(response.text).strip(' \t\r\n').replace('href="/', 'href="http://localhost:12345/') #html = str(response.text).strip(' \t\r\n').decode('utf8') html = str(response.text).strip(' \t\r\n') #pattern = r'<body>.*</body>' #start = re.search(pattern, html).start() #end = re.search(pattern, html).end() #html = html[start + 6 : end - 7] response = requests.get(self.service_url + self.css_service_endpoint_extension) css = str(response.text).strip(' \t\r\n') #if len(css) > 0: # html += '<p> The css has length ' + str(len(css)) + 'and has the content ' + css + ' </p>' #else: # html += '<p> NO CSS! </p>' #css = "#my-div{ border-style: solid; border-width: 5px; }" response = requests.get(self.service_url + self.js_service_endpoint_extension) js = str(response.text).strip(' \t\r\n') #if len(js) > 0: # html += '<p> The js has length ' + str(len(js)) + 'and has the content ' + js + ' </p>' #else: # html += '<p> NO JS! </p>' #js = 'function djangobb(runtime, element){alert("This works!");}' frag = Fragment(unicode(html).format(self=self)) frag.add_javascript(unicode(js)) frag.add_css(unicode(css)) frag.initialize_js('xdjangobb') return frag
def student_view(self, context): """ Create a fragment used to display the XBlock to a student. `context` is a dictionary used to configure the display (unused) Returns a `Fragment` object specifying the HTML, CSS, and JavaScript to display. """ provider, embed_code = self.get_embed_code_for_url(self.href) # Load the HTML fragment from within the package and fill in the template html_str = pkg_resources.resource_string(__name__, "static/html/simplevideo.html") frag = Fragment(unicode(html_str).format(self=self, embed_code=embed_code)) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/simplevideo.css") frag.add_css(unicode(css_str)) # Load JS if provider == 'vimeo.com': # Load the Froogaloop library from vimeo CDN. frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js") js_str = pkg_resources.resource_string(__name__, "static/js/simplevideo.js") frag.add_javascript(unicode(js_str)) frag.initialize_js('SimpleVideoBlock') return frag
def studio_view(self, context=None): """Studio configuration view.""" html = self.resource_string("static/html/settings.html") frag = Fragment(html.format(query=self.query)) frag.add_javascript(self.resource_string("static/js/src/settings.js")) frag.initialize_js('MKWSRefSettings') 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, '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 studio_view(self, context=None): try: cls = type(self) def none_to_empty(x): return x if x is not None else '' edit_fields = ( (field, none_to_empty(getattr(self, field.name)), validator) for field, validator in ( (cls.display_name, 'string'), (cls.points, 'number'), (cls.weight, 'number')) ) context = { 'fields': edit_fields } fragment = Fragment() fragment.add_content( render_template( 'templates/multiple_file_upload/edit.html', context ) ) fragment.add_javascript(_resource("static/js/src/studio.js")) fragment.initialize_js('MultipleFileUploadXBlock') return fragment except: # pragma: NO COVER log.error("Don't swallow my exceptions", exc_info=True) raise
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 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 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 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 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 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 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 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 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 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 student_view(self, context=None): """ The primary view of the BadgerXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/badger.html") layout_html = "" for line in transform_layout(learning_map): new_item_html = layout_line(line) layout_html = layout_html + new_item_html html = html.replace("CSS", self.resource_string("static/css/badger.css")) html = html.replace("LAYOUT", layout_html) # circle = "" # for x in range(0,101,10): # circle = circle + html_line(x, 0, 100-x, 100) # circle = circle + html_line(50, -50, 50, 150) circle = "" #html_line(0,0,0,100) + html_line(0,100,100,200) + html_line(100,200,200,200) + html_line(200,200,300,100) + html_line(300,100,300,0) html = html.replace('CIRCLE', circle) frag = Fragment(html) #frag.add_css(self.resource_string("static/css/badger.css")) frag.add_javascript(self.resource_string("static/js/src/badger.js")) frag.initialize_js('BadgerXBlock') return frag
def studio_view(self, context=None): html = self.resource_string("static/html/studio.html") frag = Fragment(html.format(self=self)) frag.add_css(self.resource_string("static/css/codecheck_tutorial.css")) frag.add_javascript(self.resource_string("static/js/src/studio.js")) frag.initialize_js('CodecheckStudioXBlock') return frag
def student_view(self, context=None): """ The primary view of VideoQuiz, shown to students. """ # load contents of quiz if any, otherwise this is just a YouTube video player if self.quiz_content != "": self.load_quiz() print("Loading Student View") print("====================") print(">> Parameters: ") print(self.quiz_content) print(self.vid_url) # print(self.width) # print(self.height) print(">> Filled data") print("Quiz entries: " + str(self.quiz)) print("Quiz cue times: " + str(self.quiz_cuetimes)) print("Answers: " + str(self.answers)) print("Results: " + str(self.results)) fragment = Fragment() fragment.add_content(render_template('templates/html/vidquiz.html', {'self': self})) fragment.add_css(load_resource('static/css/vidquiz.css')) fragment.add_javascript(load_resource('static/js/vidquiz.js')) fragment.initialize_js('VideoQuiz') return fragment
def student_view(self, context=None): # pylint: disable=W0613 template = self.resource_string("static/html/acid.html") handler_url = self.runtime.handler_url(self, "handler1") frag = Fragment(template.format(handler_url=handler_url)) frag.add_javascript(self.resource_string("static/js/src/acid.js")) frag.initialize_js('AcidBlock') return frag
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): """ The staff's view of RichReviewXBlock. Staffs can upload discussion topic PDF or view the students' discussion activities """ frag = Fragment() frag.add_css(load_resource("static/css/richreview.css")) frag.add_javascript(load_resource("static/js/src/richreview_studio.js")) frag.add_content(render_template( "templates/richreview_studio.html", { 'xblock_id': self.xblock_id, 'student_id': self.anonymous_student_id, 'user_is_staff': str(self.user_is_staff), 'students_of_group': str(self.students_of_group), 'group_of_student': str(self.group_of_student), 'discussion_docid': self.discussion_docid, 'is_pdf_ready': self.is_pdf_ready, 'is_debug': False, 'pdf_url': self.fs.get_url(self.pdf_path, RESOURCE_EXPIRATION_TIME), 'pdfjs_url': self.fs.get_url(self.pdfjs_path, RESOURCE_EXPIRATION_TIME), 'loader_gif_url': self.runtime.local_resource_url(self, "public/ajax-loader.gif") } )) frag.initialize_js('RichReviewXBlockStudio', "abcd") return frag
def student_view(self, context=None): """ The primary view of the IframeWithAnonymousIDXBlock, shown to students when viewing courses. """ student_id = self.xmodule_runtime.anonymous_student_id # student_id will be "student" if called from the Studio new_iframe_url = "{0}/{1}".format(self.iframe_url, student_id) self.display_name = new_iframe_url context = { 'self': self, 'iframe_url': new_iframe_url, 'is_in_studio': student_id == 'student' } frag = Fragment() frag.add_content(render_template('/templates/html/iframe.html', context)) frag.add_css(self.resource_string("static/css/iframe.css")) frag.add_javascript(self.resource_string("static/js/src/iframe.js")) frag.initialize_js('IframeWithAnonymousIDXBlock') return frag
def student_view(self, context=None): """ The primary view of the XBlock, shown to students when viewing courses. """ """ #添加字段记录上回播放时间,应该是用户级别的 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, "app_id": self.app_id, "file_id": self.file_id, "width": self.width, "height": self.height, } html = self.render_template("static/html/youku_view.html", context) frag = Fragment(html) # frag.add_javascript(self.load_resource('static/js/h5connect.js')) #内有中文,使用插入外部url frag.add_javascript(self.load_resource("static/js/youku_api.js")) frag.add_javascript(self.load_resource("static/js/youku_view.js")) frag.initialize_js("youkuXBlockInitView") 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(_resource("static/js/src/jquery.tablesorter.min.js")) fragment.initialize_js('StaffGradedAssignmentXBlock') 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) event_type = 'edx.pdf.loaded' event_data = { 'url': self.url, 'source_url': self.source_url, } self.runtime.publish(self, event_type, event_data) frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_view.js")) frag.initialize_js('pdfXBlockInitView') return frag
def student_view(self, context): """ Generate the html code to display the XBlock to a student `context` is a dictionary used to configure the display (unused). Returns a `Fragment` object specifying the HTML, CSS, and JavaScript to display. """ provider, embed_code = self.get_embed_code_for_url(self.href) # Retrieve HTML code for video iframe html_code = pkg_resources.resource_string(__name__, "static/html/cnvideo.html") frag = Fragment(unicode(html_code).format(self=self, embed_code=embed_code)) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/cnvideo.css") frag.add_css(css_str) # Load vimeo JS API and custom js for watching views if provider == "vimeo.com": frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js") js_str = pkg_resources.resource_string(__name__, "static/js/cnvideo.js") frag.add_javascript(unicode(js_str)) frag.initialize_js("cnVideoBlock") return frag
def student_view(self, 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=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=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=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, 'thumbnail_url': self.thumbnail_url, 'display_description': self.display_description } 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): """ XBlock student view of this component. Arguments: context (dict): XBlock context Returns: xblock.fragment.Fragment: XBlock HTML fragment """ fragment = Fragment() loader = ResourceLoader(__name__) context.update(self._get_context_for_template()) fragment.add_content( loader.render_mako_template('/templates/player.html', context)) ''' Note: DO NOT USE the "latest" folder in production, but specify a version from https://aka.ms/ampchangelog. This allows us to run a test pass prior to ingesting later versions. ''' fragment.add_css_url( '//amp.azure.net/libs/amp/1.8.1/skins/amp-default/azuremediaplayer.min.css' ) fragment.add_javascript_url( '//amp.azure.net/libs/amp/1.8.1/azuremediaplayer.min.js') fragment.add_javascript(loader.load_unicode('static/js/player.js')) fragment.add_css(loader.load_unicode('public/css/player.css')) # NOTE: The Azure Media Player JS file includes the VTT JavaScript library, so we don't # actually need to include our local copy of public/js/vendor/vtt.js. In fact, if we do # the overlay subtitles stop working # @TODO: Make sure all fields are well structured/formatted, if it is not correct, then # print out an error msg in view rather than just silently failing fragment.initialize_js('AzureMediaServicesBlock') return fragment
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_django_template( CALENDAR_EDIT_TEMPLATE, { 'self': self, 'defaultName': default_name, 'defaultID': self.fields['calendar_id']._default # pylint: disable=protected-access,unsubscriptable-object }, i18n_service=self.runtime.service(self, "i18n"), )) fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar_edit.js')) fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css')) fragment.initialize_js('GoogleCalendarEditBlock') return fragment
def student_view(self, context): # pylint: disable=unused-argument """ Player view, displayed to the student """ fragment = Fragment() fragment.add_content(RESOURCE_LOADER.render_django_template( CALENDAR_TEMPLATE, context={ "mode": self.views[self.default_view][1], "src": self.calendar_id, "title": self.display_name, "language": utils.translation.get_language(), }, i18n_service=self.runtime.service(self, "i18n"), )) fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_calendar.css')) fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar.js')) fragment.initialize_js('GoogleCalendarBlock') return fragment
def studio_view(self, context=None): context_html = self.get_context() context_html['user_id'] = self._edited_by template = self.render_template( 'static/html/studio.html', context_html) frag = Fragment(template) frag.add_css(self.resource_string("static/css/eolzoom.css")) frag.add_javascript(self.resource_string("static/js/src/studio.js")) enrolled_students = self.get_students_count( text_type(self.scope_ids.usage_id.course_key)) settings = { 'meeting_id': self.meeting_id, 'enrolled_students': enrolled_students, 'created_by': self.created_by, 'edx_created_by': self.edx_created_by, 'user_id': self._edited_by, 'course_id': text_type(self.scope_ids.usage_id.course_key), 'block_id': self.location, 'start_url': self.start_url, 'join_url': self.join_url, 'restricted_access': self.restricted_access, 'google_access': self.google_access, 'url_google_auth': reverse('auth_google'), 'url_is_logged_google': reverse('google_is_logged'), 'url_youtube_validate': reverse('youtube_validate'), 'broadcast_id': self.broadcast_id, 'url_is_logged_zoom': reverse('is_logged_zoom'), 'url_login': reverse('zoom_api'), 'url_zoom_api': '{}oauth/authorize?response_type=code&client_id={}&redirect_uri='.format( DJANGO_SETTINGS.EOLZOOM_DOMAIN, DJANGO_SETTINGS.EOLZOOM_CLIENT_ID), 'url_new_meeting': reverse('new_scheduled_meeting'), 'url_new_livebroadcast': reverse('url_new_livebroadcast'), 'url_update_livebroadcast': reverse('url_update_livebroadcast'), 'url_update_meeting': reverse('update_scheduled_meeting'), } frag.initialize_js('EolZoomStudioXBlock', json_args=settings) return frag
def studio_view(self, context): """ Render a form for editing this XBlock """ fragment = Fragment() context = {'fields': []} # Build a list of all the fields that can be edited: for field_name in self.editable_fields: 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.content = loader.render_template('templates/studio_edit.html', context) fragment.add_javascript(loader.load_unicode('public/studio_edit.js')) fragment.initialize_js('StudioEditableXBlockMixin') return fragment
def student_view(self, context): """ XBlock student view of this component. Makes a request to `lti_launch_handler` either in an iframe or in a new window depending on the configuration of the instance of this XBlock Arguments: context (dict): XBlock context Returns: xblock.fragment.Fragment: XBlock HTML fragment """ fragment = Fragment() loader = ResourceLoader(__name__) context.update(self._get_context_for_template()) fragment.add_content(loader.render_mako_template('/templates/html/student.html', context)) fragment.add_css(loader.load_unicode('static/css/student.css')) fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js')) fragment.initialize_js('LtiConsumerXBlock') 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=None): """ The primary view of the QnetXBlock, shown to students when viewing courses. """ context = { 'title': self.display_name, 'question': self.question, 'description': self.description, 'max_score': self.weight, 'score': self.score, 'is_done': self.is_done } html = self.render_template("static/html/student_view.html", context) frag = Fragment(html) frag.add_css(self.load_resource("static/css/qnet.css")) frag.add_javascript( self.load_resource("static/js/src/student_view.js")) frag.initialize_js('QnetXBlock') return frag
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 studio_view(self, context): """Create a fragment used to display the edit view in the Studio.""" context = { 'youtube_id': self.youtube_id, 'youtube_width': self.youtube_width, 'youtube_height': self.youtube_height, #'youtube_autoplay ': self.youtube_autoplay, 'youtube_autohide': self.youtube_autohide, #'youtube_cc_load_policy': self.youtube_cc_load_policy, 'youtube_color': self.youtube_color, 'youtube_controls': self.youtube_controls, 'youtube_fs': self.youtube_fs, 'youtube_hl': self.youtube_hl, 'youtube_iv_load_policy': self.youtube_iv_load_policy, 'youtube_loop': self.youtube_loop, 'youtube_modestbranding': self.youtube_modestbranding, 'youtube_rel': self.youtube_rel, 'youtube_showinfo': self.youtube_showinfo, 'youtube_theme': self.youtube_theme, 'vimeo_id': self.vimeo_id, 'vimeo_width': self.vimeo_width, 'vimeo_height': self.vimeo_height, 'vimeo_autoplay': self.vimeo_autoplay, 'vimeo_badge': self.vimeo_badge, 'vimeo_byline': self.vimeo_byline, 'vimeo_color': self.vimeo_color, 'vimeo_loop': self.vimeo_loop, 'vimeo_portrait': self.vimeo_portrait, 'vimeo_title': self.vimeo_title } frag = Fragment() template = env.get_template('embedvideos_edit.html') frag.add_content(template.render(**context)) #pylint: disable=W0142 frag.add_css(self.resource_string("static/css/embedvideos_edit.css")) frag.add_javascript(self.resource_string("static/js/src/embedvideos_edit.js")) #pylint: disable=C0301 frag.initialize_js('EmbedVideosEditXBlock') return frag
def student_view(self, context=None): """ The primary view of the CodeBrowserBlock, shown to students when viewing courses. """ student_id = self.runtime.anonymous_student_id real_user = self.runtime.get_real_user(self.runtime.anonymous_student_id) email = real_user.email """ if it is the first time for user to browser code ,the gitlab will initialize all the info """ os.system("/edx/var/edxapp/staticfiles/xblock-script/initialize_user.sh " + student_id + " " + email) """ pull the code from gitlab and generate the static html files """ os.system("/edx/var/edxapp/staticfiles/xblock-script/generator.sh " + student_id + " " + email) # Load the HTML fragment from within the package and fill in the template html_str = pkg_resources.resource_string(__name__, "static/html/codebrowser_view.html") frag = Fragment(unicode(html_str).format( width=self.width, height=self.height, student_id=student_id, email=email, )) # Load CSS css_str = pkg_resources.resource_string(__name__, "static/css/codebrowser.css") frag.add_css(unicode(css_str)) js_str = pkg_resources.resource_string(__name__, "static/js/src/codebrowser_view.js") frag.add_javascript(unicode(js_str)) frag.initialize_js('CodeBrowserViewBlock') return frag
def _render_view(self, context, view): """ Actually renders a view """ rendering_for_studio = False if context: # Workbench does not provide context rendering_for_studio = context.get('author_preview_view') fragment = Fragment() child_contents = [] for child_id in self.children: child = self.runtime.get_block(child_id) if child is None: # child should not be None but it can happen due to bugs or permission issues child_contents.append(u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))) else: if rendering_for_studio and isinstance(child, PlotBlock): # Don't use view to render plot blocks in Studio. # This is necessary because: # - student_view of plot block uses submissions API to retrieve results, # which causes "SubmissionRequestError" in Studio. # - author_preview_view does not supply JS code for plot that JS code for step depends on # (step calls "update" on plot to get latest data during rendering). child_contents.append(u"<p>{}</p>".format(child.display_name)) else: child_fragment = self._render_child_fragment(child, context, view) fragment.add_frag_resources(child_fragment) child_contents.append(child_fragment.content) fragment.add_content(loader.render_django_template('templates/html/step.html', { 'self': self, 'title': self.display_name, 'show_title': self.show_title, 'child_contents': child_contents, }, i18n_service=self.i18n_service)) fragment.add_javascript(self.get_translation_content()) fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/step.js')) fragment.initialize_js('MentoringStepBlock') return fragment
def studio_view(self, context): # pylint: disable=unused-argument """ Studio view part """ href = self.href or '' display_name = self.display_name or '' html_str = self.resource_string("static/html/officemix_edit.html") frag = Fragment( html_str.format(href=cgi.escape(href), display_name=cgi.escape(display_name))) js_str = self.resource_string("/static/js/officemix_edit.js") frag.add_javascript(js_str) css_str = self.resource_string("/static/css/officemix_edit.css") frag.add_css(css_str) frag.initialize_js('OfficeMixEditBlock') return frag
def student_view(self, context=None): """ The primary view of the CoConstructCPSXBlock, shown to students when viewing courses. """ html = self.resource_string("static/html/constructcpsxblock.html") frag = Fragment(html.format(self=self)) # No styling needed # frag.add_css(selaf.resource_string("static/css/constructcpsxblock.css")) frag.add_javascript( self.resource_string("static/js/src/constructcpsxblock.js")) # Pass module IDs to the JS source file initdict = { 'providerA': self.provider_userA, 'providerB': self.provider_userB, 'receiverA': self.receiver_userA, 'receiverB': self.receiver_userB } frag.initialize_js('CoConstructCPSXBlock', initdict) 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=None): html_edit_chart = self.resource_string("public/html/xbadge_edit.html") template = Template(html_edit_chart) html = template.render( Context({ 'nBadges': self.nBadges, 'myTitle': self.myTitle, 'myColor': self.myColor, 'myGrey': self.myGrey, 'myCourseNum': self.myCourseNum, 'myCourseRun': self.myCourseRun, 'quizPass': self.quizPass, })) frag = Fragment(html.format(self=self)) # adding references to external css and js files frag.add_css(self.resource_string("public/css/xbadge_edit.css")) frag.add_javascript( self.resource_string("public/js/src/xbadge_edit.js")) frag.initialize_js('XBadgeXBlockEdit') return frag
def student_view(self, context=None): # pylint: disable=no-member """ Student view, renders the content of LMS """ log.info("Studnent view called") log.info(self) 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) } fragment = Fragment() fragment.add_content( render_template('templates/assignment/show.html', context)) fragment.add_javascript(_resource("static/js/src/agea.js")) fragment.initialize_js('ExcelSheetAssessmentXBlock') return fragment
def create_fragment(self, html, context=None, css=None, javascript=None, initialize=None): """ Create an XBlock, given an HTML resource string and an optional context, list of CSS resource strings, list of JavaScript resource strings, and initialization function name. """ html = Template(self.resource_string(html)) context = context or {} css = css or [self.CSS_FILE] javascript = javascript or [] frag = Fragment(html.render(Context(context))) for sheet in css: frag.add_css(self.resource_string(sheet)) for script in javascript: frag.add_javascript(self.resource_string(script)) if initialize: frag.initialize_js(initialize) return frag
def student_view(self, context=None): """ The primary view of the Pumukit2XBlock, shown to students when viewing courses. """ try: pumukit_url = get_iframe_url(self.video_id) content = render_template('static/html/pumukit2.html', { 'self': self, 'pumukit_url': pumukit_url, }) frag = Fragment(content) frag.add_css(self.resource_string("static/css/pumukit2.css")) frag.add_javascript( self.resource_string("static/js/src/pumukit2.js")) frag.initialize_js('Pumukit2XBlock') except Exception as exc: html = self.resource_string("static/html/pumukit2_error.html") error_message = "{}".format(exc) frag = Fragment(html.format(error_message=error_message)) return frag
def studio_view(self, context=None): """ Studio view, renders the content of CMS """ log.info("Studio view called") log.info(self) cls = type(self) def none_to_empty(data): return data if data is not None else '' edit_fields = ((field, none_to_empty(getattr(self, field.name)), validator) for field, validator in ((cls.title, 'string'), (cls.question, 'string'), (cls.points, 'number'), (cls.weight, 'number'), (cls.max_attempts, 'number'))) context = { "studio_state": json.dumps(self.studio_state()), "id": self.location.name.replace('.', '_'), "max_file_size": getattr( settings, "STUDENT_FILEUPLOAD_MAX_SIZE", self.STUDENT_FILEUPLOAD_MAX_SIZE, ), 'fields': edit_fields } fragment = Fragment() fragment.add_content( render_template('templates/assignment/edit.html', context)) fragment.add_css(_resource("static/css/agea.css")) fragment.add_javascript(_resource("static/js/src/studio.js")) fragment.initialize_js('ExcelSheetAssessmentXBlock') return fragment
def staff_view(self): """ Primary view for instructor to Set exam using proctorU xBlock. """ api_obj = ProctoruAPI() students = api_obj.get_student_sessions(self.get_block_id()) fragment = Fragment() fragment.add_content( loader.render_template('static/html/staff-view.html', { 'self': self, 'students': students, })) 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/lms_view.js")) fragment.initialize_js('ProctoruStaffBlock') return fragment
def studio_view(self, context=None): """ The primary view of the TinyMceXBlock, shown to students when viewing courses. """ html_str = pkg_resources.resource_string(__name__, "static/html/studio_view.html") # display variables frag = Fragment(unicode(html_str).format( display_name=self.display_name, header_text=self.header_text, header_size=self.header_size, header_color=self.header_color, display_description=self.display_description, background_url=self.background_url, text_color=self.text_color, content_text=self.content_text )) frag.add_javascript(self.resource_string("static/js/src/studio_view.js")) frag.initialize_js('StudioEditSubmit') return frag
def student_view(self, context=None): # 1) Define context context = { 'display_name': self.display_name, } # It is a common mistake to define video ids suffixed with empty spaces video_id = None if self.video_id is None else self.video_id.strip() context['video'], context['messages'] = self.get_video_context( video_id) context['downloads'] = self.get_downloads_context( context['video']) if self.allow_download else [] # 2) Render template template = Template(self.resource_string("public/html/xblock.html")) content = template.render(Context(context)) # 3) Build fragment fragment = Fragment() fragment.add_content(content) fragment.add_css_url( self.runtime.local_resource_url(self, 'public/css/xblock.css')) fragment.add_css_url( self.runtime.local_resource_url( self, 'public/css/vendor/video-js.min.css')) fragment.add_javascript(self.resource_string('public/js/xblock.js')) fragment.initialize_js('VideofrontXBlock', json_args={ 'course_id': unicode(self.location.course_key) if hasattr(self, 'location') else '', 'video_id': video_id, 'video_js_url': self.runtime.local_resource_url( self, 'public/js/vendor/video.dev.js'), }) return fragment
def studio_view(self, context=None): """ The staff's view of RichReviewXBlock. Staffs can upload discussion topic PDF or view the students' discussion activities """ frag = Fragment() frag.add_css(load_resource("static/css/richreview.css")) frag.add_javascript( load_resource("static/js/src/richreview_studio.js")) frag.add_content( render_template( "templates/richreview_studio.html", { 'xblock_id': self.xblock_id, 'student_id': self.anonymous_student_id, 'user_is_staff': str(self.user_is_staff), 'students_of_group': str(self.students_of_group), 'group_of_student': str(self.group_of_student), 'discussion_docid': self.discussion_docid, 'is_pdf_ready': self.is_pdf_ready, 'is_debug': False, 'pdf_url': self.fs.get_url(self.pdf_path, RESOURCE_EXPIRATION_TIME), 'pdfjs_url': self.fs.get_url(self.pdfjs_path, RESOURCE_EXPIRATION_TIME), 'loader_gif_url': self.runtime.local_resource_url(self, "public/ajax-loader.gif") })) frag.initialize_js('RichReviewXBlockStudio', "abcd") return frag
def studio_view(self, context=None): """ The primary view of the PieChartXBlock, shown to teachers when editing the block. """ html_edit_chart = self.resource_string( "static/html/piechart_edit.html") template = Template(html_edit_chart) #merge group names and group values for easier iteration in Django template groups = [[name, value] for name, value in zip(self.groupNames, self.groupValues)] #parameters sent to browser for edit html page html = template.render( Context({ 'display_name': self.display_name, 'lengrp': len(self.groupNames), 'groups': groups, 'showLabels': self.showLabels, 'labelType': self.labelType, #current label type 'labelTypes': self.labelTypes, #list of all available label types 'labelThreshold': self.labelThreshold, 'donut': self.donut, 'width': self.width, 'height': self.height, 'startAngle': self.startAngle, 'endAngle': self.endAngle })) frag = Fragment(html.format(self=self)) #adding references to external css and js files frag.add_css(self.resource_string("static/css/piechart_edit.css")) frag.add_javascript( self.resource_string("static/js/src/piechart_edit.js")) frag.initialize_js('PieChartXBlockEdit') return frag
def studio_view(self, context=None): """ The view shown to teachers when viewing courses. """ cls = type(self) def none_to_empty(data): return data if data is not None else '' edit_fields = ((field, none_to_empty(getattr(self, field.name)), validator) for field, validator in ( (cls.display_name, 'string'), (cls.points, 'number'), (cls.weight, 'number'), (cls.question, 'string'), )) context = { "studio_state": json.dumps(self.studio_state()), "id": self.location.name.replace('.', '_'), 'fields': edit_fields } fragment = Fragment() fragment.add_content( render_template('templates/assignment/chessgridxblock_edit.html', context)) fragment.add_css(_resource("static/css/chessgridxblock.css")) fragment.add_javascript( _resource("static/js/src/chessgridxblock_edit.js")) js_str = pkg_resources.resource_string( __name__, "static/js/src/grid_library.js") fragment.add_javascript(unicode(js_str)) fragment.initialize_js('ChessgridXBlock') 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) for hotspot in hotspots: hotspot.reveal_style = 'style="{0}{1}"'.format( 'width: ' + hotspot.feedback.width + 'px;' if hotspot.feedback.width else '', 'height: ' + hotspot.feedback.height + 'px;' if hotspot.feedback.height else '') sprite_url = self.runtime.local_resource_url( self, 'public/images/hotspot-sprite.png') context = { 'title': self.display_name, 'description_html': description, 'hotspots': hotspots, 'background': background, 'sprite_url': sprite_url, } fragment = Fragment() fragment.add_content( render_template('/templates/html/image_explorer.html', context)) fragment.add_css(load_resource('public/css/image_explorer.css')) fragment.add_javascript(load_resource('public/js/image_explorer.js')) fragment.initialize_js('ImageExplorerBlock') return fragment
def studio_view(self, context=None): """ Return fragment for editing block in studio. """ try: cls = type(self) def none_to_empty(data): """ Return empty string if data is None else return data. """ return data if data is not None else '' edit_fields = ( (field, none_to_empty(getattr(self, field.name)), validator) for field, validator in ( (cls.project, 'string'), (cls.project_friendly, 'string'), ) ) context = { 'fields': edit_fields } fragment = Fragment() fragment.add_content( render_template( 'static/html/launchcontainer_edit.html', context ) ) fragment.add_javascript( load_resource("static/js/src/launchcontainer_edit.js")) fragment.initialize_js('LaunchContainerEditBlock') return fragment except: # pragma: NO COVER log.error("Don't swallow my exceptions", exc_info=True) raise
def student_view(self, context=None): """ The primary view of the ListMatchXBlock, shown to students when viewing a course. """ html = self.resource_string("static/html/listmatching.html") template = Template(html) shuffle(self.right_list) self.match_list_question['left_list'] = self.left_list self.match_list_question['right_list'] = self.right_list frag = Fragment( template.render( Context({'match_list_question': self.match_list_question}))) frag.add_css(self.resource_string("static/css/listmatching.css")) frag.add_javascript( self.resource_string("static/js/src/listmatching.js")) frag.initialize_js('ListMatchXBlock') return frag