def reload_demos(): """Reload the default widgets, then reload the default explorations.""" Widget.delete_all_widgets() InteractiveWidget.load_default_widgets() NonInteractiveWidget.load_default_widgets() Exploration.delete_demo_explorations() Exploration.load_demo_explorations()
def parse_content_into_html(content_array, block_number, params=None): """Takes a Content array and transforms it into HTML. Args: content_array: an array, each of whose members is of type Content. This object has two keys: type and value. The 'type' is one of the following: - 'text'; then the value is a text string - 'image'; then the value is an image ID - 'video'; then the value is a video ID - 'widget'; then the value is a widget ID block_number: the number of content blocks preceding this one. params: any parameters used for templatizing text strings. Returns: the HTML string representing the array. Raises: InvalidInputException: if content has no 'type' attribute, or an invalid 'type' attribute. """ if params is None: params = {} html = '' widget_array = [] widget_counter = 0 for content in content_array: if content.type == 'widget': try: widget = NonInteractiveWidget.get_with_params( content.value, params) widget_counter += 1 html += feconf.JINJA_ENV.get_template('content.html').render({ 'type': content.type, 'blockIndex': block_number, 'index': widget_counter}) widget_array.append({ 'blockIndex': block_number, 'index': widget_counter, 'code': widget.raw}) except utils.EntityIdNotFoundError: # Ignore empty widget content. pass elif (content.type in ['text', 'image', 'video']): if content.type == 'text': value = utils.parse_with_jinja(content.value, params) else: value = content.value html += feconf.JINJA_ENV.get_template('content.html').render({ 'type': content.type, 'value': value}) else: raise utils.InvalidInputException( 'Invalid content type %s', content.type) return html, widget_array