Exemplo n.º 1
0
def get_state_for_frontend(state, exploration):
    """Returns a representation of the given state for the frontend."""

    state_repr = exp_services.export_state_to_dict(exploration.id, state.id)
    modified_state_dict = exp_services.export_state_internals_to_dict(
        exploration.id, state.id, human_readable_dests=True)

    # TODO(sll): The following is for backwards-compatibility and should be
    # deleted later.
    rules = {}
    for handler in state_repr['widget']['handlers']:
        rules[handler['name']] = handler['rules']
        for item in rules[handler['name']]:
            if item['name'] == 'Default':
                item['rule'] = 'Default'
            else:
                item['rule'] = InteractiveWidget.get(
                    state.widget.widget_id).get_readable_name(
                        handler['name'], item['name']
                    )
    state_repr['widget']['rules'] = rules
    state_repr['widget']['id'] = state_repr['widget']['widget_id']

    state_repr['yaml'] = utils.yaml_from_dict(modified_state_dict)
    return state_repr
Exemplo n.º 2
0
    def post(self, exploration):
        """Adds a new state to the given exploration."""

        state_name = self.payload.get('state_name')
        if not state_name:
            raise self.InvalidInputException('Please specify a state name.')

        state = exploration.add_state(state_name)
        self.render_json(
            exp_services.export_state_to_dict(exploration.id, state.id))