def get(self, exploration_id): """Gets the data for the exploration overview page.""" # 'apply_draft' and 'v'(version) are optional parameters because the # exploration history tab also uses this handler, and these parameters # are not used by that tab. version = self.normalized_request.get('v') apply_draft = self.normalized_request.get('apply_draft') user_settings = user_services.get_user_settings(self.user_id) has_seen_editor_tutorial = False has_seen_translation_tutorial = False if user_settings is not None: if user_settings.last_started_state_editor_tutorial: has_seen_editor_tutorial = True if user_settings.last_started_state_translation_tutorial: has_seen_translation_tutorial = True try: exploration_data = exp_services.get_user_exploration_data( self.user_id, exploration_id, apply_draft=apply_draft, version=version) exploration_data['show_state_editor_tutorial_on_load'] = ( self.user_id and not has_seen_editor_tutorial) exploration_data['show_state_translation_tutorial_on_load'] = ( self.user_id and not has_seen_translation_tutorial) exploration_data['exploration_is_linked_to_story'] = ( exp_services.get_story_id_linked_to_exploration(exploration_id) is not None) except Exception as e: raise self.PageNotFoundException from e self.values.update(exploration_data) self.render_json(self.values)
def post(self, exploration_id): """Handles POST requests. Args: exploration_id: str. The ID of the exploration. """ version = self.payload.get('version') if version is None: raise self.InvalidInputException( 'NONE EXP VERSION: Maybe quit') state_name = self.payload.get('state_name') user_id = self.user_id collection_id = self.payload.get('collection_id') story_id = exp_services.get_story_id_linked_to_exploration( exploration_id) if user_id: learner_progress_services.mark_exploration_as_incomplete( user_id, exploration_id, state_name, version) if user_id and collection_id: learner_progress_services.mark_collection_as_incomplete( user_id, collection_id) if user_id and story_id: story = story_fetchers.get_story_by_id(story_id) if story is not None: learner_progress_services.record_story_started( user_id, story.id) if story.corresponding_topic_id is not None: learner_progress_services.record_topic_started( user_id, story.corresponding_topic_id) else: logging.error( 'Could not find a story corresponding to %s ' 'id.' % story_id) self.render_json({}) return event_services.MaybeLeaveExplorationEventHandler.record( exploration_id, version, state_name, self.payload.get('session_id'), self.payload.get('client_time_spent_in_secs'), self.payload.get('params'), feconf.PLAY_TYPE_NORMAL) self.render_json(self.values)