Example #1
0
    def _are_nodes_valid_for_publishing(story_nodes):
        """Validates the story nodes before publishing.

        Args:
            story_nodes: list(dict(str, *)). The list of story nodes dicts.

        Raises:
            Exception: The story node doesn't contain any exploration id or the
                exploration id is invalid or isn't published yet.
        """
        exploration_id_list = []
        for node in story_nodes:
            if not node.exploration_id:
                raise Exception('Story node with id %s does not contain an '
                                'exploration id.' % node.id)
            exploration_id_list.append(node.exploration_id)
        for exploration in exp_services.get_multiple_explorations_by_id(
                exploration_id_list):
            if exploration is None:
                raise Exception('Exploration id %s doesn\'t exist.' %
                                exploration.id)
        multiple_exploration_rights = (
            rights_manager.get_multiple_exploration_rights_by_ids(
                exploration_id_list))
        for exploration_rights in multiple_exploration_rights:
            if exploration_rights.is_private():
                raise Exception('Exploration with id %s isn\'t published.' %
                                exploration_rights.id)
Example #2
0
 def _get_explorations_states_tuples_by_ids(exp_ids):
     """Returns a list of all (exp_id, state_name) tuples for the given
     exp_ids.
     E.g. - [
       ('eid1', 'Introduction'),
       ('eid1', 'End'),
       ('eid2', 'Introduction'),
       ('eid3', 'Introduction')
     ]
     when exp_ids = ['eid1', 'eid2', 'eid3'].
     """
     explorations = (exp_services.get_multiple_explorations_by_id(
         exp_ids, strict=False))
     return [(exploration.id, state_name)
             for exploration in explorations.values()
             for state_name in exploration.states]
Example #3
0
 def _get_explorations_states_tuples_by_ids(exp_ids):
     """Returns a list of all (exp_id, state_name) tuples for the given
     exp_ids.
     E.g. - [
       ('eid1', 'Introduction'),
       ('eid1', 'End'),
       ('eid2', 'Introduction'),
       ('eid3', 'Introduction')
     ]
     when exp_ids = ['eid1', 'eid2', 'eid3'].
     """
     explorations = (
         exp_services.get_multiple_explorations_by_id(exp_ids, strict=False))
     return [
         (exploration.id, state_name)
         for exploration in explorations.values()
         for state_name in exploration.states
     ]
Example #4
0
    def map(user_model):
        user_id = user_model.id
        contributions = user_models.UserContributionsModel.get(user_id)

        created_explorations = exp_services.get_multiple_explorations_by_id(
            contributions.created_exploration_ids)
        if created_explorations:
            user_model.last_created_an_exploration = max(
                [model.created_on for model in created_explorations.values()])

        user_commits = (exp_models.ExplorationCommitLogEntryModel.query(
            exp_models.ExplorationCommitLogEntryModel.user_id == user_id
        ).order(-exp_models.ExplorationCommitLogEntryModel.created_on).fetch(1)
                        )

        if user_commits:
            user_model.last_edited_an_exploration = user_commits[0].created_on

        user_model.put()
Example #5
0
 def _are_nodes_valid_for_publishing(story_nodes):
     exploration_id_list = []
     for node in story_nodes:
         if not node.exploration_id:
             raise Exception('Story node with id %s does not contain an '
                             'exploration id.' % node.id)
         exploration_id_list.append(node.exploration_id)
     for exploration in exp_services.get_multiple_explorations_by_id(
             exploration_id_list):
         if exploration is None:
             raise Exception('Exploration id %s doesn\'t exist.' %
                             exploration.id)
     multiple_exploration_rights = (
         rights_manager.get_multiple_exploration_rights_by_ids(
             exploration_id_list))
     for exploration_rights in multiple_exploration_rights:
         if exploration_rights.is_private():
             raise Exception('Exploration with id %s isn\'t published.' %
                             exploration_rights.id)
Example #6
0
def get_exps_unresolved_answers_count_for_default_rule(exp_ids):
    """Gets answer counts per exploration for the answer groups for default
    rule across all states for explorations with ids in exp_ids.

    Note that this method currently returns the counts only for the DEFAULT
    rule. This should ideally handle all types of unresolved answers.

    Returns:
        A dict, keyed by the string '{exp_id}', whose values are the number of
        unresolved answers that exploration has. Any exp_ids for explorations
        that don't exist or that have been deleted will be ignored, and not
        included in the return value.
    """
    explorations = exp_services.get_multiple_explorations_by_id(
        exp_ids, strict=False)

    # The variable `exploration_states_tuples` is a list of all
    # (exp_id, state_name) tuples for the given exp_ids.
    # E.g. - [
    #   ('eid1', 'Introduction'),
    #   ('eid1', 'End'),
    #   ('eid2', 'Introduction'),
    #   ('eid3', 'Introduction')
    # ]
    # when exp_ids = ['eid1', 'eid2', 'eid3'].
    explorations_states_tuples = [
        (exp_domain_object.id, state_key)
        for exp_domain_object in explorations.values()
        for state_key in exp_domain_object.states
    ]
    exploration_states_answers_list = get_top_state_rule_answers_multi(
        explorations_states_tuples, [exp_domain.DEFAULT_RULESPEC_STR])
    exps_answers_mapping = {}

    for ind, statewise_answers in enumerate(exploration_states_answers_list):
        for answer in statewise_answers:
            exp_id = explorations_states_tuples[ind][0]
            if exp_id not in exps_answers_mapping:
                exps_answers_mapping[exp_id] = 0
            exps_answers_mapping[exp_id] += answer['count']

    return exps_answers_mapping
Example #7
0
def get_exps_unresolved_answers_count_for_default_rule(exp_ids):
    """Gets answer counts per exploration for the answer groups for default
    rule across all states for explorations with ids in exp_ids.

    Note that this method currently returns the counts only for the DEFAULT
    rule. This should ideally handle all types of unresolved answers.

    Returns:
        A dict, keyed by the string '{exp_id}', whose values are the number of
        unresolved answers that exploration has. Any exp_ids for explorations
        that don't exist or that have been deleted will be ignored, and not
        included in the return value.
    """
    explorations = exp_services.get_multiple_explorations_by_id(exp_ids,
                                                                strict=False)

    # The variable `exploration_states_tuples` is a list of all
    # (exp_id, state_name) tuples for the given exp_ids.
    # E.g. - [
    #   ('eid1', 'Introduction'),
    #   ('eid1', 'End'),
    #   ('eid2', 'Introduction'),
    #   ('eid3', 'Introduction')
    # ]
    # when exp_ids = ['eid1', 'eid2', 'eid3'].
    explorations_states_tuples = [
        (exp_domain_object.id, state_key)
        for exp_domain_object in explorations.values()
        for state_key in exp_domain_object.states
    ]
    exploration_states_answers_list = get_top_state_rule_answers_multi(
        explorations_states_tuples, [exp_domain.DEFAULT_RULESPEC_STR])
    exps_answers_mapping = {}

    for ind, statewise_answers in enumerate(exploration_states_answers_list):
        for answer in statewise_answers:
            exp_id = explorations_states_tuples[ind][0]
            if exp_id not in exps_answers_mapping:
                exps_answers_mapping[exp_id] = 0
            exps_answers_mapping[exp_id] += answer['count']

    return exps_answers_mapping
    def map(user_model):
        user_id = user_model.id
        contributions = user_models.UserContributionsModel.get(user_id)

        created_explorations = exp_services.get_multiple_explorations_by_id(
            contributions.created_exploration_ids)
        if created_explorations:
            user_model.last_created_an_exploration = max(
                [model.created_on for model in created_explorations.values()])

        user_commits = (
            exp_models.ExplorationCommitLogEntryModel.query(
                exp_models.ExplorationCommitLogEntryModel.user_id == user_id).
            order(-exp_models.ExplorationCommitLogEntryModel.created_on).
            fetch(1))

        if user_commits:
            user_model.last_edited_an_exploration = user_commits[0].created_on

        user_model.put()