def _load_extra_content(self, system, course_descriptor, category, path, course_dir): for filepath in glob.glob(path / '*'): if not os.path.isfile(filepath): continue with open(filepath) as f: try: html = f.read().decode('utf-8') # tabs are referenced in policy.json through a 'slug' which is just the filename without the .html suffix slug = os.path.splitext(os.path.basename(filepath))[0] loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, category, slug) module = HtmlDescriptor(system, loc, {'data': html}) # VS[compat]: # Hack because we need to pull in the 'display_name' for static tabs (because we need to edit them) # from the course policy if category == "static_tab": for tab in course_descriptor.tabs or []: if tab.get('url_slug') == slug: module.display_name = tab['name'] module.data_dir = course_dir self.modules[course_descriptor.id][ module.location] = module except Exception, e: logging.exception( "Failed to load {0}. Skipping... Exception: {1}". format(filepath, str(e))) system.error_tracker("ERROR: " + str(e))
def _load_extra_content(self, system, course_descriptor, category, path, course_dir): for filepath in glob.glob(path / '*'): if not os.path.isfile(filepath): continue with open(filepath) as f: try: html = f.read().decode('utf-8') # tabs are referenced in policy.json through a 'slug' which is just the filename without the .html suffix slug = os.path.splitext(os.path.basename(filepath))[0] loc = Location('i4x', course_descriptor.location.org, course_descriptor.location.course, category, slug) module = HtmlDescriptor(system, {'data': html, 'location': loc}) # VS[compat]: # Hack because we need to pull in the 'display_name' for static tabs (because we need to edit them) # from the course policy if category == "static_tab": for tab in course_descriptor.tabs or []: if tab.get('url_slug') == slug: module.display_name = tab['name'] module.data_dir = course_dir self.modules[course_descriptor.id][module.location] = module except Exception, e: logging.exception("Failed to load {0}. Skipping... Exception: {1}".format(filepath, str(e))) system.error_tracker("ERROR: " + str(e))
def _section_send_email(course_id, access, course): """ Provide data for the corresponding bulk email section """ html_module = HtmlDescriptor( course.system, DictFieldData({'data': ''}), ScopeIds(None, None, None, 'i4x://dummy_org/dummy_course/html/dummy_name')) fragment = course.system.render(html_module, 'studio_view') fragment = wrap_xblock(partial(handler_prefix, course_id), html_module, 'studio_view', fragment, None) email_editor = fragment.content section_data = { 'section_key': 'send_email', 'section_display_name': _('Email'), 'access': access, 'send_email': reverse('send_email', kwargs={'course_id': course_id}), 'editor': email_editor, 'list_instructor_tasks_url': reverse('list_instructor_tasks', kwargs={'course_id': course_id}), 'email_background_tasks_url': reverse('list_background_email_tasks', kwargs={'course_id': course_id}), } return section_data
def _section_send_email(course_key, access, course): """ Provide data for the corresponding bulk email section """ html_module = HtmlDescriptor( course.system, DictFieldData({'data': ''}), ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake')) ) fragment = course.system.render(html_module, 'studio_view') fragment = wrap_xblock( 'LmsRuntime', html_module, 'studio_view', fragment, None, extra_data={"course-id": course_key.to_deprecated_string()}, usage_id_serializer=lambda usage_id: quote_slashes(usage_id.to_deprecated_string()) ) email_editor = fragment.content section_data = { 'section_key': 'send_email', 'section_display_name': _('Email'), 'access': access, 'send_email': reverse('send_email', kwargs={'course_id': course_key.to_deprecated_string()}), 'editor': email_editor, 'list_instructor_tasks_url': reverse( 'list_instructor_tasks', kwargs={'course_id': course_key.to_deprecated_string()} ), 'email_background_tasks_url': reverse( 'list_background_email_tasks', kwargs={'course_id': course_key.to_deprecated_string()} ), } return section_data
def _section_send_email(course_key, access, course): """ Provide data for the corresponding bulk email section """ # This HtmlDescriptor is only being used to generate a nice text editor. html_module = HtmlDescriptor( course.system, DictFieldData({'data': ''}), ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake')) ) fragment = course.system.render(html_module, 'studio_view') fragment = wrap_xblock( 'LmsRuntime', html_module, 'studio_view', fragment, None, extra_data={"course-id": course_key.to_deprecated_string()}, usage_id_serializer=lambda usage_id: quote_slashes(usage_id.to_deprecated_string()), # Generate a new request_token here at random, because this module isn't connected to any other # xblock rendering. request_token=uuid.uuid1().get_hex() ) email_editor = fragment.content section_data = { 'section_key': 'send_email', 'section_display_name': _('Email'), 'access': access, 'send_email': reverse('send_email', kwargs={'course_id': course_key.to_deprecated_string()}), 'editor': email_editor, 'list_instructor_tasks_url': reverse( 'list_instructor_tasks', kwargs={'course_id': course_key.to_deprecated_string()} ), 'email_background_tasks_url': reverse( 'list_background_email_tasks', kwargs={'course_id': course_key.to_deprecated_string()} ), 'email_content_history_url': reverse( 'list_email_content', kwargs={'course_id': course_key.to_deprecated_string()} ), } return section_data
def _section_send_email(course, access): """ Provide data for the corresponding bulk email section """ course_key = course.id # Monkey-patch applicable_aside_types to return no asides for the duration of this render with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types): # This HtmlDescriptor is only being used to generate a nice text editor. html_module = HtmlDescriptor( course.system, DictFieldData({'data': ''}), ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))) fragment = course.system.render(html_module, 'studio_view') fragment = wrap_xblock( 'LmsRuntime', html_module, 'studio_view', fragment, None, extra_data={"course-id": unicode(course_key)}, usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)), # Generate a new request_token here at random, because this module isn't connected to any other # xblock rendering. request_token=uuid.uuid1().get_hex()) cohorts = [] if is_course_cohorted(course_key): cohorts = get_course_cohorts(course) email_editor = fragment.content section_data = { 'section_key': 'send_email', 'section_display_name': _('Email'), 'access': access, 'send_email': reverse('send_email', kwargs={'course_id': unicode(course_key)}), 'editor': email_editor, 'cohorts': cohorts, 'default_cohort_name': DEFAULT_COHORT_NAME, 'list_instructor_tasks_url': reverse('list_instructor_tasks', kwargs={'course_id': unicode(course_key)}), 'email_background_tasks_url': reverse('list_background_email_tasks', kwargs={'course_id': unicode(course_key)}), 'email_content_history_url': reverse('list_email_content', kwargs={'course_id': unicode(course_key)}), } return section_data
def test_get_some_templates(self): self.assertEqual(len(SequenceDescriptor.templates()), 0) self.assertGreater(len(HtmlDescriptor.templates()), 0) self.assertIsNone(SequenceDescriptor.get_template("doesntexist.yaml")) self.assertIsNone(HtmlDescriptor.get_template("doesntexist.yaml")) self.assertIsNotNone(HtmlDescriptor.get_template("announcement.yaml"))
def test_get_some_templates(self): self.assertEqual(len(SequenceDescriptor.templates()), 0) self.assertGreater(len(HtmlDescriptor.templates()), 0) self.assertIsNone(SequenceDescriptor.get_template('doesntexist.yaml')) self.assertIsNone(HtmlDescriptor.get_template('doesntexist.yaml')) self.assertIsNotNone(HtmlDescriptor.get_template('announcement.yaml'))