Exemple #1
0
    def post(self, user):
        """Handles POST requests."""

        payload = json.loads(self.request.get('payload'))

        title = payload.get('title')
        category = payload.get('category')

        if not title:
            raise self.InvalidInputException('No title supplied.')
        if not category:
            raise self.InvalidInputException('No category chosen.')

        yaml = self.request.get('yaml')

        if yaml and feconf.ALLOW_YAML_FILE_UPLOAD:
            exploration = Exploration.create_from_yaml(
                yaml_file=yaml, user=user, title=title, category=category)
        else:
            exploration = Exploration.create(
                user, title=title, category=category)

        self.response.write(json.dumps({
            'explorationId': exploration.id,
        }))
Exemple #2
0
    def post(self, user):
        """Handles POST requests."""

        payload = json.loads(self.request.get('payload'))

        exploration_id = payload.get('exploration_id')

        forked_exploration = Exploration.get(exploration_id)
        if not forked_exploration.is_demo_exploration():
            raise self.InvalidInputException('Exploration cannot be forked.')

        # Get the demo exploration as a YAML file, so that new states can be
        # created.
        yaml = forked_exploration.as_yaml()
        title = 'Copy of %s' % forked_exploration.title
        category = forked_exploration.category

        exploration = Exploration.create_from_yaml(
            yaml_file=yaml, user=user, title=title, category=category)

        self.response.write(json.dumps({
            'explorationId': exploration.id,
        }))