當前位置: 首頁>>代碼示例>>Python>>正文


Python EdxRestApiClient.accounts方法代碼示例

本文整理匯總了Python中edx_rest_api_client.client.EdxRestApiClient.accounts方法的典型用法代碼示例。如果您正苦於以下問題:Python EdxRestApiClient.accounts方法的具體用法?Python EdxRestApiClient.accounts怎麽用?Python EdxRestApiClient.accounts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在edx_rest_api_client.client.EdxRestApiClient的用法示例。


在下文中一共展示了EdxRestApiClient.accounts方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: account_details

# 需要導入模塊: from edx_rest_api_client.client import EdxRestApiClient [as 別名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import accounts [as 別名]
    def account_details(self, request):
        """ Returns the account details from LMS.

        Args:
            request (WSGIRequest): The request from which the LMS account API endpoint is created.

        Returns:
            A dictionary of account details.

        Raises:
            ConnectionError, SlumberBaseException and Timeout for failures in establishing a
            connection with the LMS account API endpoint.
        """
        try:
            api = EdxRestApiClient(
                request.site.siteconfiguration.build_lms_url('/api/user/v1'),
                append_slash=False,
                jwt=request.site.siteconfiguration.access_token
            )
            response = api.accounts(self.username).get()
            return response
        except (ConnectionError, SlumberBaseException, Timeout):
            log.exception(
                'Failed to retrieve account details for [%s]',
                self.username
            )
            raise
開發者ID:open-craft,項目名稱:ecommerce,代碼行數:29,代碼來源:models.py

示例2: is_verified

# 需要導入模塊: from edx_rest_api_client.client import EdxRestApiClient [as 別名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import accounts [as 別名]
    def is_verified(self, site):
        """
        Check if a user has verified his/her identity.
        Calls the LMS verification status API endpoint and returns the verification status information.
        The status information is stored in cache, if the user is verified, until the verification expires.

        Args:
            site (Site): The site object from which the LMS account API endpoint is created.

        Returns:
            True if the user is verified, false otherwise.

        Raises:
            ConnectionError, SlumberBaseException and Timeout for failures in
            establishing a connection with the LMS verification status API endpoint.
        """
        try:
            cache_key = 'verification_status_{username}'.format(username=self.username)
            cache_key = hashlib.md5(cache_key).hexdigest()
            verification = cache.get(cache_key)
            if not verification:
                api = EdxRestApiClient(
                    site.siteconfiguration.build_lms_url('api/user/v1/'),
                    oauth_access_token=self.access_token
                )
                response = api.accounts(self.username).verification_status().get()

                verification = response.get('is_verified', False)
                if verification:
                    cache_timeout = int((parse(response.get('expiration_datetime')) - now()).total_seconds())
                    cache.set(cache_key, verification, cache_timeout)
            return verification
        except HttpNotFoundError:
            log.debug('No verification data found for [%s]', self.username)
            return False
        except (ConnectionError, SlumberBaseException, Timeout):
            msg = 'Failed to retrieve verification status details for [{username}]'.format(username=self.username)
            log.exception(msg)
            raise VerificationStatusError(msg)
開發者ID:open-craft,項目名稱:ecommerce,代碼行數:41,代碼來源:models.py


注:本文中的edx_rest_api_client.client.EdxRestApiClient.accounts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。