def __getattr__(self, name): if self._my_answer == UNANSWERED: raise errors.IllegalState('this Item has not been attempted') if self._my_answer == NULL_SUBMISSION: raise errors.IllegalState('this Item has been skipped or cleared') if not name.startswith('__'): try: return getattr(self._my_answer, name) except: raise
def get_correctness(self, question_id): """get measure of correctness for the question""" response = self.get_response(question_id) if response.is_answered(): item = self._get_item(response.get_item_id()) return item.get_correctness_for_response(response) raise errors.IllegalState()
def get_commenting_agent(self): """Gets the agent who created this comment. return: (osid.authentication.Agent) - the ``Agent`` raise: OperationFailed - unable to complete request *compliance: mandatory -- This method must be implemented.* """ if not self.has_commentor(): raise errors.IllegalState('this Comment has no commenting_agent') try: from ..authentication import managers except ImportError: raise errors.OperationFailed( 'failed to import authentication.managers') try: mgr = managers.AuthenticationManager() except: raise errors.OperationFailed( 'failed to instantiate AuthenticationManager') if not mgr.supports_agent_lookup(): raise errors.OperationFailed( 'Authentication does not support Agent lookup') try: osid_object = mgr.get_agent_lookup_session().get_agent( self.get_commenting_agent_id()) except: raise errors.OperationFailed() else: return osid_object
def is_correct(self, question_id): """is the question answered correctly""" response = self.get_response(question_id=question_id) if response.is_answered(): item = self._get_item(response.get_item_id()) return item.is_response_correct(response) raise errors.IllegalState()
def get_next_locales(self, n): """Gets the next set of ``Locale`` elements in this list. The specified amount must be less than or equal to the return from ``available()``. arg: n (cardinal): the number of ``Locale`` elements requested which must be less than or equal to ``available()`` return: (osid.locale.Locale) - an array of ``Locale`` elements.The length of the array is less than or equal to the number specified. raise: IllegalState - no more elements available in this list raise: OperationFailed - unable to complete request *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.ResourceList.get_next_resources if n > self.available(): # !!! This is not quite as specified (see method docs) !!! raise errors.IllegalState( 'not enough elements available in this list') else: next_list = [] i = 0 while i < n: try: next_list.append(self.next()) except StopIteration: break i += 1 return next_list
def get_confused_learning_objective_ids(self, question_id): """get confused objective ids available for the question""" response = self.get_response(question_id) if response.is_answered(): item = self._get_item(response.get_item_id()) return item.get_confused_learning_objective_ids_for_response( response) raise errors.IllegalState()
def _initialize_manager(self, runtime): """Sets the runtime, configuration and json client""" if self._runtime is not None: raise errors.IllegalState( 'this manager has already been initialized.') self._runtime = runtime self._config = runtime.get_configuration() set_json_client(runtime)
def get_next_question(self, question_id, answered=None, reverse=False, honor_sequential=True): """Inspects question map to return the next available question. if answered == False: only return next unanswered question if answered == True: only return next answered question if answered in None: return next question whether answered or not if reverse == True: go backwards - effectively get_previous_question if honor_sequential == True: only return questions if section or part is set to sequential items """ self._update_questions() # Make sure questions list is current question_map = self._get_question_map( question_id) # will raise NotFound() questions = list(self._my_map['questions']) if reverse: questions = questions[::-1] error_text = ' previous ' else: if 'missingResponse' in question_map: if self._is_question_sequential( question_map) and honor_sequential: raise errors.IllegalState( 'Next question is not yet available') error_text = ' next ' if questions[-1] == question_map: raise errors.IllegalState('No ' + error_text + ' questions available') index = questions.index(question_map) + 1 for question_map in questions[index:]: latest_question_response = question_map['responses'][0] question_answered = False # take missingResponse == UNANSWERED or NULL_RESPONSE as an unanswered question if 'missingResponse' not in latest_question_response: question_answered = True if answered is None or question_answered == answered: return self.get_question(question_map=question_map) raise errors.IllegalState('No ' + error_text + ' question matching parameters was found')
def get_child_assessment_part_ids(self): """Gets any child assessment part ``Ids``. return: (osid.id.IdList) - ``Ids`` of the child assessment parts *compliance: mandatory -- This method must be implemented.* """ if not self.has_children(): raise errors.IllegalState('no children assessment parts') return IdList(self._my_map['childIds'])
def get_assessment_part_id(self): """Gets the parent assessment ``Id``. return: (osid.id.Id) - ``Id`` of an assessment raise: IllegalState - ``has_parent_part()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if not self.has_parent_part(): raise errors.IllegalState('no parent part') return Id(self._my_map['assessmentPartId'])
def get_assessment_part_id(self): """Gets the assessment part ``Id`` to which this rule belongs. return: (osid.id.Id) - ``Id`` of an assessment part *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.learning.Activity.get_objective_id if not bool(self._my_map['assessmentPartId']): raise errors.IllegalState('assessment_part empty') return Id(self._my_map['assessmentPartId'])
def get_provider_id(self): """Gets the ``Id`` of the provider. return: (osid.id.Id) - the provider ``Id`` *compliance: mandatory -- This method must be implemented.* """ if 'providerId' not in self._my_map or not self._my_map['providerId']: raise errors.IllegalState( 'this sourceable object has no provider set') return Id(self._my_map['providerId'])
def get_qualifier_id(self): """Gets the ``Qualifier Id`` for this authorization. return: (osid.id.Id) - the qualifier ``Id`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.learning.Activity.get_objective_id if not bool(self._my_map['qualifierId']): raise errors.IllegalState('qualifier empty') return Id(self._my_map['qualifierId'])
def get_families(self): """Gets the family list resulting from a search. return: (osid.relationship.FamilyList) - the family list raise: IllegalState - list already retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.FamilyList(self._results, runtime=self._runtime)
def get_hierarchies(self): """Gets the hierarchy list resulting from the search. return: (osid.hierarchy.HierarchyList) - the hierarchy list raise: IllegalState - the hierarchy list was already retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.HierarchyList(self._results, runtime=self._runtime)
def get_grade_systems(self): """Gets the grade system list resulting from the search. return: (osid.grading.GradeSystemList) - the grade system list raise: IllegalState - list already retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.GradeSystemList(self._results, runtime=self._runtime)
def get_effective_date(self): """Gets the effective date. return: (timestamp) - the effective date raise: IllegalState - ``has_effective_date()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if self.has_effective_date(): return self._effective_date else: raise errors.IllegalState()
def get_agents(self): """Gets the agent list resulting from the search. return: (osid.authentication.AgentList) - the agent list raise: IllegalState - list already retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.AgentList(self._results, runtime=self._runtime)
def get_agent_id(self): """Gets the agent ``Id`` who created this entry. return: (osid.id.Id) - the agent ``Id`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.Resource.get_avatar_id_template if not bool(self._my_map['agentId']): raise errors.IllegalState('this LogEntry has no agent') else: return Id(self._my_map['agentId'])
def get_format_type(self): """Gets the ``DisplayText`` format ``Type``. return: (osid.type.Type) - the format ``Type`` raise: IllegalState - ``has_format_type()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if self.has_format_type(): return self._format_type else: raise errors.IllegalState()
def get_effective_clock_rate(self): """Gets the rate of the clock. return: (decimal) - the rate raise: IllegalState - ``has_effective_date()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if self.has_effective_date(): return self._effective_clock_rate else: raise errors.IllegalState()
def get_priority(self): """Gets the priority level of this entry. return: (osid.type.Type) - the priority level *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.logging.LogEntry.get_priority if not self._my_map['priority']: raise errors.IllegalState('this LogEntry has no priority') else: return Id(self._my_map['priority'])
def get_assets(self): """Gets the asset list resulting from a search. return: (osid.repository.AssetList) - the asset list raise: IllegalState - the list has already been retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.AssetList(self._results, runtime=self._runtime)
def get_effective_agent_id(self): """Gets the effective ``Agent Id`` for this proxy. return: (osid.id.Id) - the effective agent ``Id`` raise: IllegalState - ``has_effective_agent()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if self.has_effective_agent(): return self._effective_agent_id else: raise errors.IllegalState()
def get_resource_id(self): """Gets the ``resource _id`` for this authorization. return: (osid.id.Id) - the ``Resource Id`` raise: IllegalState - ``has_resource()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.Resource.get_avatar_id_template if not bool(self._my_map['resourceId']): raise errors.IllegalState('this Authorization has no resource') else: return Id(self._my_map['resourceId'])
def get_sequence_rules(self): """Gets the ``SequenceRuleList`` resulting from a search. return: (osid.assessment.authoring.SequenceRuleList) - the sequence rule list raise: IllegalState - list has already been retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.SequenceRuleList(self._results, runtime=self._runtime)
def get_avatar_id(self): """Gets the asset ``Id``. return: (osid.id.Id) - the asset ``Id`` raise: IllegalState - ``has_avatar()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.Resource.get_avatar_id_template if not bool(self._my_map['avatarId']): raise errors.IllegalState('this Resource has no avatar') else: return Id(self._my_map['avatarId'])
def get_authentication(self): """Gets the ``Authentication`` for this proxy. return: (osid.authentication.process.Authentication) - the authentication raise: IllegalState - ``has_authentication()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ if self.has_authentication(): return self._authentication else: raise errors.IllegalState()
def get_objective_banks(self): """Gets the objective bank list resulting from the search. return: (osid.learning.ObjectiveBankList) - the objective bank list raise: IllegalState - list already retrieved *compliance: mandatory -- This method must be implemented.* """ if self.retrieved: raise errors.IllegalState('List has already been retrieved.') self.retrieved = True return objects.ObjectiveBankList(self._results, runtime=self._runtime)
def get_rating_id(self): """Gets the ``Id`` of the ``Grade``. return: (osid.id.Id) - the ``Agent`` ``Id`` raise: IllegalState - ``has_rating()`` is ``false`` *compliance: mandatory -- This method must be implemented.* """ # Implemented from template for osid.resource.Resource.get_avatar_id_template if not bool(self._my_map['ratingId']): raise errors.IllegalState('this Comment has no rating') else: return Id(self._my_map['ratingId'])