コード例 #1
0
 def query_statements(self, query):
     """Query the LRS for statements with specified parameters
     :param query: Dictionary of query parameters and their values
     :type query: dict
     :return: LRS Response object with the returned StatementsResult object as content
     :rtype: :class:`tincan.lrs_response.LRSResponse`
     .. note::
        Optional query parameters are\n
            **statementId:** (*str*) ID of the Statement to fetch
            **voidedStatementId:** (*str*) ID of the voided Statement to fetch
            **agent:** (*Agent* |*Group*) Filter to return Statements for which the
            specified Agent or Group is the Actor
            **verb:** (*Verb id IRI*) Filter to return Statements matching the verb id
            **activity:** (*Activity id IRI*) Filter to return Statements for which the
            specified Activity is the Object
            **registration:** (*UUID*) Filter to return Statements matching the specified registration ID
            **related_activities:** (*bool*) Include Statements for which the Object,
            Context Activities or any Sub-Statement
            properties match the specified Activity
            **related_agents:** (*bool*) Include Statements for which the Actor, Object,
            Authority, Instructor, Team, or any Sub-Statement properties match the specified Agent
            **since:** (*datetime*) Filter to return Statements stored since the specified datetime
            **until:** (*datetime*) Filter to return Statements stored at or before the specified datetime
            **limit:** (*positive int*) Allow <limit> Statements to be returned. 0 indicates the
            maximum supported by the LRS
            **format:** (*str* {"ids"|"exact"|"canonical"}) Manipulates how the LRS handles
            importing and returning the statements
            **attachments:** (*bool*) If true, the LRS will use multipart responses and include
            all attachment data per Statement returned.
            Otherwise, application/json is used and no attachment information will be returned
            **ascending:** (*bool*) If true, the LRS will return results in ascending order of
            stored time (oldest first)
     """
     params = {}
     param_keys = [
         "registration",
         "since",
         "until",
         "limit",
         "ascending",
         "related_activities",
         "related_agents",
         "format",
         "attachments",
     ]
     for k, v in query.items():
         if v is not None:
             if k == "agent":
                 params[k] = v.to_json(self.version)
             elif k == "verb" or k == "activity":
                 params[k] = v.id
             elif k in param_keys:
                 params[k] = v
     request = HTTPRequest(method="GET", resource="statements")
     request.query_params = params
     lrs_response = self._send_request(request)
     if lrs_response.success:
         lrs_response.content = StatementsResult.from_json(
             lrs_response.data)
     return lrs_response
コード例 #2
0
 def more_statements(self, more_url):
     """Query the LRS for more statements
     :param more_url: URL from a StatementsResult object used to retrieve more statements
     :type more_url: str | unicode
     :return: LRS Response object with the returned StatementsResult object as content
     :rtype: :class:`tincan.lrs_response.LRSResponse`
     """
     if isinstance(more_url, StatementsResult):
         more_url = more_url.more
     more_url = self.get_endpoint_server_root() + more_url
     request = HTTPRequest(method="GET", resource=more_url)
     lrs_response = self._send_request(request)
     if lrs_response.success:
         lrs_response.content = StatementsResult.from_json(
             lrs_response.data)
     return lrs_response
コード例 #3
0
ファイル: remote_lrs.py プロジェクト: FishHooks/TinCanPython
    def query_statements(self, query):
        """Query the LRS for statements with specified parameters

        :param query: Dictionary of query parameters and their values
        :type query: dict
        :return: LRS Response object with the returned StatementsResult object as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        params = {}

        param_keys = [
            "registration",
            "since",
            "until",
            "limit",
            "ascending",
            "related_activities",
            "related_agents",
            "format",
            "attachments",
        ]

        for k, v in query.iteritems():
            if v is not None:
                if k == "agent":
                    params[k] = v.to_json(self.version)
                elif k == "verb" or k == "activity":
                    params[k] = v.id
                elif k in param_keys:
                    params[k] = v

        request = HTTPRequest(
            method="GET",
            resource="statements"
        )
        request.query_params = params

        lrs_response = self._send_request(request)

        if lrs_response.success:
            lrs_response.content = StatementsResult.from_json(lrs_response.data)

        return lrs_response
コード例 #4
0
    def more_statements(self, more_url):
        """Query the LRS for more statements

        :param more_url: URL from a StatementsResult object used to retrieve more statements
        :type more_url: str | unicode
        :return: LRS Response object with the returned StatementsResult object as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        if isinstance(more_url, StatementsResult):
            more_url = more_url.more

        more_url = self.get_endpoint_server_root() + more_url

        request = HTTPRequest(
            method="GET",
            resource=more_url
        )

        lrs_response = self._send_request(request)

        if lrs_response.success:
            lrs_response.content = StatementsResult.from_json(lrs_response.data)

        return lrs_response
コード例 #5
0
    def query_statements(self, query):
        """Query the LRS for statements with specified parameters

        :param query: Dictionary of query parameters and their values
        :type query: dict
        :return: LRS Response object with the returned StatementsResult object as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`

        .. note::
           Optional query parameters are\n
               **statementId:** (*str*) ID of the Statement to fetch
               **voidedStatementId:** (*str*) ID of the voided Statement to fetch
               **agent:** (*Agent* |*Group*) Filter to return Statements for which the
               specified Agent or Group is the Actor
               **verb:** (*Verb id IRI*) Filter to return Statements matching the verb id
               **activity:** (*Activity id IRI*) Filter to return Statements for which the
               specified Activity is the Object
               **registration:** (*UUID*) Filter to return Statements matching the specified registration ID
               **related_activities:** (*bool*) Include Statements for which the Object,
               Context Activities or any Sub-Statement
               properties match the specified Activity
               **related_agents:** (*bool*) Include Statements for which the Actor, Object,
               Authority, Instructor, Team, or any Sub-Statement properties match the specified Agent
               **since:** (*datetime*) Filter to return Statements stored since the specified datetime
               **until:** (*datetime*) Filter to return Statements stored at or before the specified datetime
               **limit:** (*positive int*) Allow <limit> Statements to be returned. 0 indicates the
               maximum supported by the LRS
               **format:** (*str* {"ids"|"exact"|"canonical"}) Manipulates how the LRS handles
               importing and returning the statements
               **attachments:** (*bool*) If true, the LRS will use multipart responses and include
               all attachment data per Statement returned.
               Otherwise, application/json is used and no attachment information will be returned
               **ascending:** (*bool*) If true, the LRS will return results in ascending order of
               stored time (oldest first)
        """
        params = {}

        param_keys = [
            "registration",
            "since",
            "until",
            "limit",
            "ascending",
            "related_activities",
            "related_agents",
            "format",
            "attachments",
        ]

        for k, v in query.iteritems():
            if v is not None:
                if k == "agent":
                    params[k] = v.to_json(self.version)
                elif k == "verb" or k == "activity":
                    params[k] = v.id
                elif k in param_keys:
                    params[k] = v

        request = HTTPRequest(
            method="GET",
            resource="statements"
        )
        request.query_params = params

        lrs_response = self._send_request(request)

        if lrs_response.success:
            lrs_response.content = StatementsResult.from_json(lrs_response.data)

        return lrs_response