当前位置: 首页>>代码示例>>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;未经允许,请勿转载。