当前位置: 首页>>代码示例>>Python>>正文


Python EdxRestApiClient.courses方法代码示例

本文整理汇总了Python中edx_rest_api_client.client.EdxRestApiClient.courses方法的典型用法代码示例。如果您正苦于以下问题:Python EdxRestApiClient.courses方法的具体用法?Python EdxRestApiClient.courses怎么用?Python EdxRestApiClient.courses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edx_rest_api_client.client.EdxRestApiClient的用法示例。


在下文中一共展示了EdxRestApiClient.courses方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _publish_creditcourse

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def _publish_creditcourse(self, course_id, access_token):
        """Creates or updates a CreditCourse object on the LMS."""

        api = EdxRestApiClient(
            get_lms_url('api/credit/v1/'),
            oauth_access_token=access_token,
            timeout=self.timeout
        )

        data = {
            'course_key': course_id,
            'enabled': True
        }

        api.courses(course_id).put(data)
开发者ID:10clouds,项目名称:ecommerce,代码行数:17,代码来源:publishers.py

示例2: refresh_all_course_api_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def refresh_all_course_api_data(cls, access_token):
        course_api_url = settings.COURSES_API_URL
        client = EdxRestApiClient(course_api_url, oauth_access_token=access_token)

        count = None
        page = 1

        logger.info('Refreshing course api data from %s....', course_api_url)

        while page:
            # TODO Update API to not require username?
            response = client.courses().get(page=page, page_size=50, username='ecommerce_worker')
            count = response['pagination']['count']
            results = response['results']
            logger.info('Retrieved %d courses...', len(results))

            if response['pagination']['next']:
                page += 1
            else:
                page = None

            for body in results:
                Course(body['id']).update(body)

        logger.info('Retrieved %d courses from %s.', count, course_api_url)
开发者ID:eduStack,项目名称:course-discovery,代码行数:27,代码来源:models.py

示例3: refresh_all

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def refresh_all(cls, access_token):
        """
        Refresh all course data.

        Args:
            access_token (str): OAuth access token

        Returns:
            None
        """
        client = EdxRestApiClient(settings.ECOMMERCE_API_URL, oauth_access_token=access_token)

        logger.info('Refreshing course data from %s....', settings.ECOMMERCE_API_URL)

        count = None
        page = 1
        while page:
            response = client.courses().get(include_products=True, page=page, page_size=50)
            count = response['count']
            results = response['results']
            logger.info('Retrieved %d courses...', len(results))

            if response['next']:
                page += 1
            else:
                page = None

            for body in results:
                Course(body['id'], body).save()

        logger.info('Retrieved %d courses.', count)
开发者ID:wkoha,项目名称:course-discovery,代码行数:33,代码来源:models.py

示例4: get_context_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def get_context_data(self, **kwargs):
        context = super(CouponOfferView, self).get_context_data(**kwargs)

        code = self.request.GET.get('code', None)
        if code is not None:
            voucher, product = get_voucher(code=code)
            valid_voucher, msg = voucher_is_valid(voucher, product, self.request)
            if valid_voucher:
                api = EdxRestApiClient(
                    get_lms_url('api/courses/v1/'),
                )
                try:
                    course = api.courses(product.course_id).get()
                except SlumberHttpBaseException as e:
                    logger.exception('Could not get course information. [%s]', e)
                    return {
                        'error': _('Could not get course information. [{error}]'.format(error=e))
                    }

                course['image_url'] = get_lms_url(course['media']['course_image']['uri'])
                stock_records = voucher.offers.first().benefit.range.catalog.stock_records.first()
                context.update({
                    'course': course,
                    'code': code,
                    'price': stock_records.price_excl_tax,
                    'verified': (product.attr.certificate_type is 'verified')
                })
                return context
            return {
                'error': msg
            }
        return {
            'error': _('This coupon code is invalid.')
        }
开发者ID:arbrandes,项目名称:edx-ecommerce,代码行数:36,代码来源:views.py

示例5: get_course_info_from_lms

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
def get_course_info_from_lms(course_key):
    """ Get course information from LMS via the course api and cache """
    api = EdxRestApiClient(get_lms_url('api/courses/v1/'))
    cache_key = 'courses_api_detail_{}'.format(course_key)
    cache_hash = hashlib.md5(cache_key).hexdigest()
    course = cache.get(cache_hash)
    if not course:  # pragma: no cover
        course = api.courses(course_key).get()
        cache.set(cache_hash, course, settings.COURSES_API_CACHE_TIMEOUT)
    return course
开发者ID:siddhartharay007,项目名称:ecommerce,代码行数:12,代码来源:utils.py

示例6: get_context_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
 def get_context_data(self, **kwargs):
     context = super(CouponOfferView, self).get_context_data(**kwargs)
     footer = get_lms_footer()
     code = self.request.GET.get('code', None)
     if code is not None:
         voucher, product = get_voucher_from_code(code=code)
         valid_voucher, msg = voucher_is_valid(voucher, product, self.request)
         if valid_voucher:
             api = EdxRestApiClient(
                 get_lms_url('api/courses/v1/'),
             )
             try:
                 course = api.courses(product.course_id).get()
             except SlumberHttpBaseException as e:
                 logger.exception('Could not get course information. [%s]', e)
                 return {
                     'error': _('Could not get course information. [{error}]'.format(error=e)),
                     'footer': footer
                 }
             course['image_url'] = get_lms_url(course['media']['course_image']['uri'])
             benefit = voucher.offers.first().benefit
             stock_record = benefit.range.catalog.stock_records.first()
             price = stock_record.price_excl_tax
             context.update(get_voucher_discount_info(benefit, price))
             if benefit.type == 'Percentage':
                 new_price = price - (price * (benefit.value / 100))
             else:
                 new_price = price - benefit.value
                 if new_price < 0:
                     new_price = Decimal(0)
             context.update({
                 'benefit': benefit,
                 'course': course,
                 'code': code,
                 'is_discount_value_percentage': benefit.type == 'Percentage',
                 'is_enrollment_code': benefit.type == Benefit.PERCENTAGE and benefit.value == 100.00,
                 'discount_value': "%.2f" % (price - new_price),
                 'price': price,
                 'new_price': "%.2f" % new_price,
                 'verified': (product.attr.certificate_type == 'verified'),
                 'verification_deadline': product.course.verification_deadline,
                 'footer': footer
             })
             return context
         return {
             'error': msg,
             'footer': footer
         }
     return {
         'error': _('This coupon code is invalid.'),
         'footer': footer
     }
开发者ID:pjha1994,项目名称:ecommerce-1,代码行数:54,代码来源:views.py

示例7: CatalogApiService

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
class CatalogApiService(object):
    """The service to interface with edX catalog API"""

    def __init__(self, access_token, oauth_host, oauth_key, oauth_secret, api_url_root):
        self.access_token = access_token
        if not access_token:
            logger.info('No access token provided. Retrieving access token using client_credential flow...')
            try:
                self.access_token, expires = EdxRestApiClient.get_oauth_access_token(
                    '{root}/access_token'.format(root=oauth_host),
                    oauth_key,
                    oauth_secret, token_type='jwt'
                )
            except Exception:
                logger.exception('No access token provided or acquired through client_credential flow.')
                raise

            logger.info('Token retrieved: %s', access_token)

        self.api_client = EdxRestApiClient(api_url_root, jwt=self.access_token)
        self._programs_dictionary = {}

    def _get_resource_from_api(self, api_endpoint, page_size, **kwargs):
        page = 0
        results = []

        while page >= 0:
            response = api_endpoint.get(limit=page_size, offset=(page * page_size), **kwargs)
            if response.get('next'):
                page += 1
            else:
                page = -1
            results.extend(response.get('results'))

        return results

    def get_courses(self):
        logger.debug('Get Courses called')
        return self._get_resource_from_api(self.api_client.courses(), COURSES_PAGE_SIZE, marketable=1)

    def get_program_dictionary(self):
        if not self._programs_dictionary:
            program_array = self._get_resource_from_api(
                self.api_client.programs(),
                PROGRAMS_PAGE_SIZE,
                marketable=1,
                published_course_runs_only=1
            )
            for program in program_array:
                self._programs_dictionary[program['uuid']] = program
        return self._programs_dictionary
开发者ID:edx,项目名称:ecommerce-scripts,代码行数:53,代码来源:catalog_api_service.py

示例8: _get_courses_enrollment_info

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def _get_courses_enrollment_info(self):
        """
        Retrieve the enrollment information for all the courses.

        Returns:
            Dictionary representing the key-value pair (course_key, enrollment_end) of course.
        """
        def _parse_response(api_response):
            response_data = api_response.get('results', [])

            # Map course_id with enrollment end date.
            courses_enrollment = dict(
                (course_info['course_id'], course_info['enrollment_end'])
                for course_info in response_data
            )
            return courses_enrollment, api_response['pagination'].get('next', None)

        querystring = {'page_size': 50}
        api = EdxRestApiClient(get_lms_url('api/courses/v1/'))
        course_enrollments = {}

        page = 0
        throttling_attempts = 0
        next_page = True
        while next_page:
            page += 1
            querystring['page'] = page
            try:
                response = api.courses().get(**querystring)
                throttling_attempts = 0
            except HttpClientError as exc:
                # this is a known limitation; If we get HTTP429, we need to pause execution for a few seconds
                # before re-requesting the data. raise any other errors
                if exc.response.status_code == 429 and throttling_attempts < self.max_tries:
                    logger.warning(
                        'API calls are being rate-limited. Waiting for [%d] seconds before retrying...',
                        self.pause_time
                    )
                    time.sleep(self.pause_time)
                    page -= 1
                    throttling_attempts += 1
                    logger.info('Retrying [%d]...', throttling_attempts)
                    continue
                else:
                    raise
            enrollment_info, next_page = _parse_response(response)
            course_enrollments.update(enrollment_info)
        return course_enrollments
开发者ID:10clouds,项目名称:ecommerce,代码行数:50,代码来源:update_course_seat_expire.py

示例9: refresh

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def refresh(cls, course_id, access_token):
        """
        Refresh the course data from the raw data sources.

        Args:
            course_id (str): Course ID
            access_token (str): OAuth access token

        Returns:
            Course
        """
        client = EdxRestApiClient(settings.ECOMMERCE_API_URL, oauth_access_token=access_token)
        body = client.courses(course_id).get(include_products=True)
        course = Course(course_id, body)
        course.save()
        return course
开发者ID:wkoha,项目名称:course-discovery,代码行数:18,代码来源:models.py

示例10: get_context_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def get_context_data(self, **kwargs):
        context = super(BasketSummaryView, self).get_context_data(**kwargs)
        lines = context.get('line_list', [])
        api = EdxRestApiClient(get_lms_url('api/courses/v1/'))
        for line in lines:
            course_id = line.product.course_id

            # Get each course type so we can display to the user at checkout.
            try:
                line.certificate_type = get_certificate_type_display_value(line.product.attr.certificate_type)
            except ValueError:
                line.certificate_type = None

            cache_key = 'courses_api_detail_{}'.format(course_id)
            cache_hash = hashlib.md5(cache_key).hexdigest()
            try:
                course = cache.get(cache_hash)
                if not course:
                    course = api.courses(course_id).get()
                    course['image_url'] = get_lms_url(course['media']['course_image']['uri'])
                    cache.set(cache_hash, course, settings.COURSES_API_CACHE_TIMEOUT)
                line.course = course
            except (ConnectionError, SlumberBaseException, Timeout):
                logger.exception('Failed to retrieve data from Course API for course [%s].', course_id)

            if line.has_discount:
                line.discount_percentage = line.discount_value / line.unit_price_incl_tax * Decimal(100)
            else:
                line.discount_percentage = 0

        context.update({
            'payment_processors': self.get_payment_processors(),
            'homepage_url': get_lms_url(''),
            'footer': get_lms_footer(),
            'lines': lines,
            'faq_url': get_lms_url('') + '/verified-certificate',
        })
        return context
开发者ID:pjha1994,项目名称:ecommerce-1,代码行数:40,代码来源:views.py

示例11: refresh_all_ecommerce_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def refresh_all_ecommerce_data(cls, access_token):
        ecommerce_api_url = settings.ECOMMERCE_API_URL
        client = EdxRestApiClient(ecommerce_api_url, oauth_access_token=access_token)
        count = None
        page = 1

        logger.info('Refreshing ecommerce data from %s....', ecommerce_api_url)

        while page:
            response = client.courses().get(include_products=True, page=page, page_size=50)
            count = response['count']
            results = response['results']
            logger.info('Retrieved %d courses...', len(results))

            if response['next']:
                page += 1
            else:
                page = None

            for body in results:
                Course(body['id']).update(body)

        logger.info('Retrieved %d courses from %s.', count, ecommerce_api_url)
开发者ID:eduStack,项目名称:course-discovery,代码行数:25,代码来源:models.py

示例12: get_context_data

# 需要导入模块: from edx_rest_api_client.client import EdxRestApiClient [as 别名]
# 或者: from edx_rest_api_client.client.EdxRestApiClient import courses [as 别名]
    def get_context_data(self, **kwargs):
        context = super(BasketSummaryView, self).get_context_data(**kwargs)
        formset = context.get('formset', [])
        lines = context.get('line_list', [])
        lines_data = []
        api = EdxRestApiClient(get_lms_url('api/courses/v1/'))
        is_verification_required = False
        for line in lines:
            course_key = CourseKey.from_string(line.product.attr.course_key)
            cache_key = 'courses_api_detail_{}'.format(course_key)
            cache_hash = hashlib.md5(cache_key).hexdigest()
            course_name = None
            image_url = None
            short_description = None
            try:
                course = cache.get(cache_hash)
                if not course:
                    course = api.courses(course_key).get()
                    cache.set(cache_hash, course, settings.COURSES_API_CACHE_TIMEOUT)
                image_url = get_lms_url(course['media']['course_image']['uri'])
                short_description = course['short_description']
                course_name = course['name']
            except (ConnectionError, SlumberBaseException, Timeout):
                logger.exception('Failed to retrieve data from Course API for course [%s].', course_key)

            if line.has_discount:
                benefit = self.request.basket.applied_offers().values()[0].benefit
                benefit_value = format_benefit_value(benefit)
            else:
                benefit_value = None

            lines_data.append({
                'seat_type': self._determine_seat_type(line.product),
                'course_name': course_name,
                'course_key': course_key,
                'image_url': image_url,
                'course_short_description': short_description,
                'benefit_value': benefit_value,
                'enrollment_code': line.product.get_product_class().name == ENROLLMENT_CODE_PRODUCT_CLASS_NAME,
                'line': line,
            })

            context.update({
                'analytics_data': prepare_analytics_data(
                    self.request.user,
                    self.request.site.siteconfiguration.segment_key,
                    unicode(course_key)
                ),
            })

            # Check product attributes to determine if ID verification is required for this basket
            try:
                is_verification_required = is_verification_required or line.product.attr.id_verification_required
            except AttributeError:
                pass

        context.update({
            'free_basket': context['order_total'].incl_tax == 0,
            'payment_processors': self.request.site.siteconfiguration.get_payment_processors(),
            'homepage_url': get_lms_url(''),
            'formset_lines_data': zip(formset, lines_data),
            'is_verification_required': is_verification_required,
        })
        return context
开发者ID:digideskio,项目名称:ecommerce-2,代码行数:66,代码来源:views.py


注:本文中的edx_rest_api_client.client.EdxRestApiClient.courses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。