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_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 post(self): """Saves an image uploaded by a content creator.""" raw = self.request.get('image') if raw: image_id = Image.create(raw) self.render_json({'image_id': image_id}) else: raise self.InvalidInputException('No image supplied')