示例#1
0
    def post(self, exploration_id):
        """Handles POST requests. Appends to existing list of playthroughs or
        deletes it if already full.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        issue_schema_version = self.payload.get('issue_schema_version')
        if issue_schema_version is None:
            raise self.InvalidInputException('missing issue_schema_version')

        playthrough_data = self.payload.get('playthrough_data')
        try:
            playthrough = stats_domain.Playthrough.from_dict(playthrough_data)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        exp_issues = stats_services.get_exp_issues_from_model(
            stats_models.ExplorationIssuesModel.get_model(
                exploration_id, playthrough.exp_version))

        if self._assign_playthrough_to_corresponding_issue(
                playthrough, exp_issues, issue_schema_version):
            stats_services.save_exp_issues_model_transactional(exp_issues)
        self.render_json({})
示例#2
0
    def post(self, exploration_id):
        """Handles POST requests. Appends to existing list of playthroughs or
        deletes it if already full.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        exp_issue_dict = self.payload.get('exp_issue_dict')
        self._require_exp_issue_dict_is_valid(exp_issue_dict)

        playthrough_data = self.payload.get('playthrough_data')
        self._require_playthrough_data_is_valid(playthrough_data)

        exp_issues_model = stats_models.ExplorationIssuesModel.get(
            exploration_id)
        exp_issues = stats_services.get_exp_issues_from_model(exp_issues_model)

        customization_args = exp_issue_dict['issue_customization_args']

        issue_found = False
        for index, issue in enumerate(exp_issues.unresolved_issues):
            if issue.issue_type == exp_issue_dict['issue_type']:
                issue_customization_args = issue.issue_customization_args
                # In case issue_keyname is 'state_names', the ordering of the
                # list is important i.e. [a,b,c] is different from [b,c,a].
                issue_keyname = stats_models.ISSUE_TYPE_KEYNAME_MAPPING[
                    issue.issue_type]
                if (issue_customization_args[issue_keyname] ==
                        customization_args[issue_keyname]):
                    issue_found = True
                    if (len(issue.playthrough_ids) <
                            feconf.MAX_PLAYTHROUGHS_FOR_ISSUE):
                        playthrough_id = stats_models.PlaythroughModel.create(
                            playthrough_data['exp_id'],
                            playthrough_data['exp_version'],
                            playthrough_data['issue_type'],
                            playthrough_data['issue_customization_args'],
                            playthrough_data['playthrough_actions'],
                            playthrough_data['is_valid'])
                        exp_issues.unresolved_issues[
                            index].playthrough_ids.append(playthrough_id)
                    break

        if not issue_found:
            playthrough_id = stats_models.PlaythroughModel.create(
                playthrough_data['exp_id'], playthrough_data['exp_version'],
                playthrough_data['issue_type'],
                playthrough_data['issue_customization_args'],
                playthrough_data['playthrough_actions'],
                playthrough_data['is_valid'])
            issue = stats_domain.ExplorationIssue(
                exp_issue_dict['issue_type'],
                exp_issue_dict['issue_customization_args'], [playthrough_id],
                exp_issue_dict['schema_version'])

            exp_issues.unresolved_issues.append(issue)

        stats_services.save_exp_issues_model_transactional(exp_issues)
        self.render_json({})
示例#3
0
    def post(self, exp_id):
        """Handles POST requests."""
        exp_issue_dict = self.payload.get('exp_issue_dict')
        try:
            unused_exp_issue = stats_domain.ExplorationIssue.from_dict(
                exp_issue_dict)
        except utils.ValidationError as e:
            raise self.PageNotFoundException(e)

        exp_version = self.payload.get('exp_version')

        exp_issues = stats_services.get_exp_issues(exp_id, exp_version)
        if exp_issues is None:
            raise self.PageNotFoundException(
                'Invalid exploration ID %s' % (exp_id))

        # Check that the passed in issue actually exists in the exploration
        # issues instance.
        issue_to_remove = None
        for issue in exp_issues.unresolved_issues:
            if issue.to_dict() == exp_issue_dict:
                issue_to_remove = issue
                break

        if not issue_to_remove:
            raise self.PageNotFoundException(
                'Exploration issue does not exist in the list of issues for '
                'the exploration with ID %s' % exp_id)

        # Remove the issue from the unresolved issues list.
        exp_issues.unresolved_issues.remove(issue_to_remove)

        # Update the exploration issues instance and delete the playthrough
        # instances.
        stats_services.delete_playthroughs_multi(
            issue_to_remove.playthrough_ids)
        stats_services.save_exp_issues_model_transactional(exp_issues)

        self.render_json({})
示例#4
0
    def post(self, exploration_id):
        """Handles POST requests. Appends to existing list of playthroughs or
        deletes it if already full.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        playthrough_data = self.payload.get('playthrough_data')
        try:
            unused_playthrough = stats_domain.Playthrough.from_backend_dict(
                playthrough_data)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        try:
            self.current_issue_schema_version = self.payload[
                'issue_schema_version']
        except KeyError as e:
            raise self.InvalidInputException(e)

        try:
            self.current_playthrough_id = self.payload['playthrough_id']
        except KeyError as e:
            raise self.InvalidInputException(e)

        exp_version = playthrough_data['exp_version']

        exp_issues_model = stats_models.ExplorationIssuesModel.get_model(
            exploration_id, exp_version)
        self.current_exp_issues = stats_services.get_exp_issues_from_model(
            exp_issues_model)

        playthrough = stats_domain.Playthrough.from_dict(playthrough_data)

        # If playthrough already exists, update it in the datastore.
        if self.current_playthrough_id is not None:
            orig_playthrough = stats_services.get_playthrough_by_id(
                self.current_playthrough_id)
            if orig_playthrough.issue_type != playthrough.issue_type:
                self._move_playthrough_to_correct_issue(
                    playthrough, orig_playthrough)

            stats_services.update_playthroughs_multi(
                [self.current_playthrough_id], [playthrough])
            stats_services.save_exp_issues_model_transactional(
                self.current_exp_issues)
            self.render_json({})
            return

        payload_return = {'playthrough_stored': True}

        playthrough_id = None
        try:
            playthrough_id = self._assign_playthrough_to_issue(playthrough)
        except Exception:
            payload_return['playthrough_stored'] = False

        stats_services.save_exp_issues_model_transactional(
            self.current_exp_issues)
        payload_return['playthrough_id'] = playthrough_id
        self.render_json(payload_return)