def get(self, exploration): """Handles GET requests.""" filename = 'oppia-%s' % utils.to_ascii(exploration.title) if not filename: filename = feconf.DEFAULT_FILE_NAME self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Content-Disposition'] = ( 'attachment; filename=%s.txt' % filename) self.response.write(exp_services.export_to_yaml(exploration.id))
def post(self): """Handles POST requests.""" exploration_id = self.payload.get('exploration_id') forked_exploration = Exploration.get(exploration_id) if not forked_exploration.is_demo: raise self.InvalidInputException('Exploration cannot be forked.') # Get the demo exploration as a YAML file, so that new states can be # created. yaml_content = exp_services.export_to_yaml(forked_exploration.id) title = 'Copy of %s' % forked_exploration.title category = forked_exploration.category new_exploration_id = exp_services.create_from_yaml( yaml_content, self.user_id, title, category) self.render_json({'explorationId': new_exploration_id})
def test_export_to_yaml(self): """Test the export_to_yaml() method.""" exploration = Exploration.get( exp_services.create_new(self.owner_id, "A title", "A category", "A different exploration_id") ) exploration.add_state("New state") yaml_content = exp_services.export_to_yaml(exploration.id) self.assertEqual( yaml_content, """parameters: [] states: - content: [] name: '[untitled state]' param_changes: [] widget: handlers: - name: submit rules: - dest: '[untitled state]' feedback: [] inputs: {} name: Default param_changes: [] params: {} sticky: false widget_id: interactive-Continue - content: [] name: New state param_changes: [] widget: handlers: - name: submit rules: - dest: New state feedback: [] inputs: {} name: Default param_changes: [] params: {} sticky: false widget_id: interactive-Continue """, )