def load_demos(): """Initializes the demo explorations.""" for index, exploration in enumerate(feconf.DEMO_EXPLORATIONS): if len(exploration) == 3: (exp_filename, title, category) = exploration image_filename = None elif len(exploration) == 4: (exp_filename, title, category, image_filename) = exploration else: raise Exception('Invalid demo exploration: %s' % exploration) image_id = None if image_filename: image_filepath = os.path.join( feconf.SAMPLE_IMAGES_DIR, image_filename) image_id = Image.create(utils.get_file_contents( image_filepath, raw_bytes=True)) yaml_content = utils.get_sample_exploration_yaml(exp_filename) exploration_id = create_from_yaml( yaml_content, None, title, category, exploration_id=str(index), image_id=image_id) exploration = Exploration.get(exploration_id) exploration.is_public = True exploration.put()
def load_demo_explorations(cls): """Initializes the demo explorations.""" for index, exploration in enumerate(feconf.DEMO_EXPLORATIONS): assert len(exploration) in [3, 4], ( 'Invalid format for demo exploration: %s' % exploration) yaml_filename = '%s.yaml' % exploration[0] yaml_file = utils.get_file_contents( os.path.join(feconf.SAMPLE_EXPLORATIONS_DIR, yaml_filename)) title = exploration[1] category = exploration[2] image_filename = exploration[3] if len(exploration) == 4 else None image_id = None if image_filename: with open(os.path.join( feconf.SAMPLE_IMAGES_DIR, image_filename)) as f: raw_image = f.read() image_id = Image.create(raw_image) exploration = cls.create_from_yaml( yaml_file=yaml_file, user=None, title=title, category=category, exploration_id=str(index), image_id=image_id) exploration.is_public = True exploration.put()
def load_default_widgets(cls): """Loads the default widgets.""" widget_ids = os.listdir(feconf.NONINTERACTIVE_WIDGETS_DIR) for widget_id in widget_ids: widget_dir = os.path.join( feconf.NONINTERACTIVE_WIDGETS_DIR, widget_id) widget_conf_filename = '%s.config.yaml' % widget_id with open(os.path.join(widget_dir, widget_conf_filename)) as f: conf = utils.dict_from_yaml(f.read().decode('utf-8')) conf['id'] = '%s-%s' % (feconf.NONINTERACTIVE_PREFIX, widget_id) conf['params'] = [Parameter(**param) for param in conf['params']] # TODO(sll): Should this be a template *location* instead? conf['template'] = utils.get_file_contents( os.path.join(widget_dir, '%s.html' % widget_id)) widget = cls(**conf) widget.put()
def load_default_widgets(cls): """Loads the default widgets. Assumes that everything is valid (directories exist, widget config files are formatted correctly, etc.). """ widget_ids = os.listdir(feconf.INTERACTIVE_WIDGETS_DIR) for widget_id in widget_ids: widget_dir = os.path.join(feconf.INTERACTIVE_WIDGETS_DIR, widget_id) widget_conf_filename = '%s.config.yaml' % widget_id with open(os.path.join(widget_dir, widget_conf_filename)) as f: conf = utils.dict_from_yaml(f.read().decode('utf-8')) conf['id'] = '%s-%s' % (feconf.INTERACTIVE_PREFIX, widget_id) conf['params'] = [Parameter(**param) for param in conf['params']] conf['handlers'] = [AnswerHandler(**ah) for ah in conf['handlers']] conf['template'] = utils.get_file_contents( os.path.join(widget_dir, '%s.html' % widget_id)) widget = cls(**conf) widget.put()