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


Python RequestCache.get_request_cache方法代码示例

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


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

示例1: get_group_info_for_cohort

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def get_group_info_for_cohort(cohort, use_cached=False):
    """
    Get the ids of the group and partition to which this cohort has been linked
    as a tuple of (int, int).

    If the cohort has not been linked to any group/partition, both values in the
    tuple will be None.

    The partition group info is cached for the duration of a request. Pass
    use_cached=True to use the cached value instead of fetching from the
    database.
    """
    request_cache = RequestCache.get_request_cache()
    cache_key = u"cohorts.get_group_info_for_cohort.{}".format(cohort.id)

    if use_cached and cache_key in request_cache.data:
        return request_cache.data[cache_key]

    request_cache.data.pop(cache_key, None)

    try:
        partition_group = CourseUserGroupPartitionGroup.objects.get(course_user_group=cohort)
        return request_cache.data.setdefault(cache_key, (partition_group.group_id, partition_group.partition_id))
    except CourseUserGroupPartitionGroup.DoesNotExist:
        pass

    return request_cache.data.setdefault(cache_key, (None, None))
开发者ID:189140879,项目名称:edx-platform,代码行数:29,代码来源:cohorts.py

示例2: create_modulestore_instance

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def create_modulestore_instance(engine, doc_store_config, options, i18n_service=None):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = get_cache('mongo_metadata_inheritance')
    except InvalidCacheBackendError:
        metadata_inheritance_cache = get_cache('default')

    return class_(
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        modulestore_update_signal=Signal(providing_args=['modulestore', 'course_id', 'location']),
        xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
        xblock_select=getattr(settings, 'XBLOCK_SELECT_FUNCTION', None),
        doc_store_config=doc_store_config,
        i18n_service=i18n_service or ModuleI18nService(),
        **_options
    )
开发者ID:BeiLuoShiMen,项目名称:edx-platform,代码行数:35,代码来源:django.py

示例3: create_modulestore_instance

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def create_modulestore_instance(engine, options):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = get_cache('mongo_metadata_inheritance')
    except InvalidCacheBackendError:
        metadata_inheritance_cache = get_cache('default')

    return class_(
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        modulestore_update_signal=Signal(providing_args=['modulestore', 'course_id', 'location']),
        **_options
    )
开发者ID:NikolayStrekalov,项目名称:edx-platform,代码行数:31,代码来源:django.py

示例4: handle

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def handle(self, *args, **options):
        "Execute the command"
        if len(args) != 2:
            raise CommandError("clone requires two arguments: <source-course_id> <dest-course_id>")

        source_course_id = args[0]
        dest_course_id = args[1]

        mstore = modulestore('direct')
        cstore = contentstore()

        mstore.metadata_inheritance_cache_subsystem = CACHE
        mstore.request_cache = RequestCache.get_request_cache()
        org, course_num, run = dest_course_id.split("/")
        mstore.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))

        print("Cloning course {0} to {1}".format(source_course_id, dest_course_id))

        source_location = CourseDescriptor.id_to_location(source_course_id)
        dest_location = CourseDescriptor.id_to_location(dest_course_id)

        if clone_course(mstore, cstore, source_location, dest_location):
            # be sure to recompute metadata inheritance after all those updates
            mstore.refresh_cached_metadata_inheritance_tree(dest_location)

            print("copying User permissions...")
            _copy_course_group(source_location, dest_location)
开发者ID:Negotiare,项目名称:edx-platform,代码行数:29,代码来源:clone_course.py

示例5: get_template_request_context

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def get_template_request_context():
    """
    Returns the template processing context to use for the current request,
    or returns None if there is not a current request.
    """
    request = getattr(REQUEST_CONTEXT, "request", None)
    if not request:
        return None

    request_cache_dict = RequestCache.get_request_cache().data
    cache_key = "edxmako_request_context"
    if cache_key in request_cache_dict:
        return request_cache_dict[cache_key]

    context = RequestContext(request)
    context['is_secure'] = request.is_secure()
    context['site'] = safe_get_host(request)

    # This used to happen when a RequestContext object was initialized but was
    # moved to a different part of the logic when template engines were introduced.
    # Since we are not using template engines we do this here.
    # https://github.com/django/django/commit/37505b6397058bcc3460f23d48a7de9641cd6ef0
    for processor in get_template_context_processors():
        context.update(processor(request))

    request_cache_dict[cache_key] = context

    return context
开发者ID:10clouds,项目名称:edx-platform,代码行数:30,代码来源:middleware.py

示例6: handle

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1 and len(args) != 2:
            raise CommandError("delete_course requires one or more arguments: <location> |commit|")

        course_id = args[0]

        commit = False
        if len(args) == 2:
            commit = args[1] == 'commit'

        if commit:
            print 'Actually going to delete the course from DB....'

        ms = modulestore('direct')
        cs = contentstore()

        ms.metadata_inheritance_cache_subsystem = CACHE
        ms.request_cache = RequestCache.get_request_cache()
        org, course_num, run = course_id.split("/")
        ms.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))

        if query_yes_no("Deleting course {0}. Confirm?".format(course_id), default="no"):
            if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
                loc = CourseDescriptor.id_to_location(course_id)
                if delete_course(ms, cs, loc, commit):
                    print 'removing User permissions from course....'
                    # in the django layer, we need to remove all the user permissions groups associated with this course
                    if commit:
                        _delete_course_group(loc)
开发者ID:Negotiare,项目名称:edx-platform,代码行数:31,代码来源:delete_course.py

示例7: create_modulestore_instance

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def create_modulestore_instance(
    engine,
    content_store,
    doc_store_config,
    options,
    i18n_service=None,
    fs_service=None,
    user_service=None,
    signal_handler=None,
):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    FUNCTION_KEYS = ["render_template"]
    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = get_cache("mongo_metadata_inheritance")
    except InvalidCacheBackendError:
        metadata_inheritance_cache = get_cache("default")

    if issubclass(class_, MixedModuleStore):
        _options["create_modulestore_instance"] = create_modulestore_instance

    if issubclass(class_, BranchSettingMixin):
        _options["branch_setting_func"] = _get_modulestore_branch_setting

    if HAS_USER_SERVICE and not user_service:
        xb_user_service = DjangoXBlockUserService(get_current_user())
    else:
        xb_user_service = None

    if "read_preference" in doc_store_config:
        doc_store_config["read_preference"] = getattr(ReadPreference, doc_store_config["read_preference"])

    return class_(
        contentstore=content_store,
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        xblock_mixins=getattr(settings, "XBLOCK_MIXINS", ()),
        xblock_select=getattr(settings, "XBLOCK_SELECT_FUNCTION", None),
        doc_store_config=doc_store_config,
        i18n_service=i18n_service or ModuleI18nService(),
        fs_service=fs_service or xblock.reference.plugins.FSService(),
        user_service=user_service or xb_user_service,
        signal_handler=signal_handler or SignalHandler(class_),
        **_options
    )
开发者ID:rhndg,项目名称:openedx,代码行数:62,代码来源:django.py

示例8: handle

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("check_course requires one argument: <location>")

        loc_str = args[0]

        loc = CourseDescriptor.id_to_location(loc_str)
        store = modulestore()

        # setup a request cache so we don't throttle the DB with all the metadata inheritance requests
        store.set_modulestore_configuration({
            'metadata_inheritance_cache_subsystem': CACHE,
            'request_cache': RequestCache.get_request_cache()
        })

        course = store.get_item(loc, depth=3)

        err_cnt = 0

        def _xlint_metadata(module):
            err_cnt = check_module_metadata_editability(module)
            for child in module.get_children():
                err_cnt = err_cnt + _xlint_metadata(child)
            return err_cnt

        err_cnt = err_cnt + _xlint_metadata(course)

        # we've had a bug where the xml_attributes field can we rewritten as a string rather than a dict
        def _check_xml_attributes_field(module):
            err_cnt = 0
            if hasattr(module, 'xml_attributes') and isinstance(module.xml_attributes, basestring):
                print 'module = {0} has xml_attributes as a string. It should be a dict'.format(module.location.url())
                err_cnt = err_cnt + 1
            for child in module.get_children():
                err_cnt = err_cnt + _check_xml_attributes_field(child)
            return err_cnt

        err_cnt = err_cnt + _check_xml_attributes_field(course)

        # check for dangling discussion items, this can cause errors in the forums
        def _get_discussion_items(module):
            discussion_items = []
            if module.location.category == 'discussion':
                discussion_items = discussion_items + [module.location.url()]

            for child in module.get_children():
                discussion_items = discussion_items + _get_discussion_items(child)

            return discussion_items

        discussion_items = _get_discussion_items(course)

        # now query all discussion items via get_items() and compare with the tree-traversal
        queried_discussion_items = store.get_items(['i4x', course.location.org, course.location.course,
                                                    'discussion', None, None])

        for item in queried_discussion_items:
            if item.location.url() not in discussion_items:
                print 'Found dangling discussion module = {0}'.format(item.location.url())
开发者ID:LukeLu1263,项目名称:edx-platform,代码行数:61,代码来源:check_course.py

示例9: get_cohort

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def get_cohort(user, course_key, assign=True, use_cached=False):
    """Returns the user's cohort for the specified course.

    The cohort for the user is cached for the duration of a request. Pass
    use_cached=True to use the cached value instead of fetching from the
    database.

    Arguments:
        user: a Django User object.
        course_key: CourseKey
        assign (bool): if False then we don't assign a group to user
        use_cached (bool): Whether to use the cached value or fetch from database.

    Returns:
        A CourseUserGroup object if the course is cohorted and the User has a
        cohort, else None.

    Raises:
       ValueError if the CourseKey doesn't exist.
    """
    request_cache = RequestCache.get_request_cache()
    cache_key = u"cohorts.get_cohort.{}.{}".format(user.id, course_key)

    if use_cached and cache_key in request_cache.data:
        return request_cache.data[cache_key]

    request_cache.data.pop(cache_key, None)

    # First check whether the course is cohorted (users shouldn't be in a cohort
    # in non-cohorted courses, but settings can change after course starts)
    course_cohort_settings = get_course_cohort_settings(course_key)
    if not course_cohort_settings.is_cohorted:
        return request_cache.data.setdefault(cache_key, None)

    # If course is cohorted, check if the user already has a cohort.
    try:
        membership = CohortMembership.objects.get(
            course_id=course_key,
            user_id=user.id,
        )
        return request_cache.data.setdefault(cache_key, membership.course_user_group)
    except CohortMembership.DoesNotExist:
        # Didn't find the group. If we do not want to assign, return here.
        if not assign:
            # Do not cache the cohort here, because in the next call assign
            # may be True, and we will have to assign the user a cohort.
            return None

    # Otherwise assign the user a cohort.
    membership = CohortMembership.objects.create(
        user=user,
        course_user_group=get_random_cohort(course_key)
    )
    return request_cache.data.setdefault(cache_key, membership.course_user_group)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:56,代码来源:cohorts.py

示例10: _bookmarks_cache

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def _bookmarks_cache(self, course_key, fetch=False):
        """
        Return the user's bookmarks cache for a particular course.

        Arguments:
            course_key (CourseKey): course_key of the course whose bookmarks cache should be returned.
            fetch (Bool): if the bookmarks should be fetched and cached if they already aren't.
        """
        store = modulestore()
        course_key = store.fill_in_run(course_key)
        if course_key.run is None:
            return []
        cache_key = CACHE_KEY_TEMPLATE.format(self._user.id, course_key)

        bookmarks_cache = RequestCache.get_request_cache().data.get(cache_key, None)
        if bookmarks_cache is None and fetch is True:
            bookmarks_cache = api.get_bookmarks(
                self._user, course_key=course_key, fields=DEFAULT_FIELDS
            )
            RequestCache.get_request_cache().data[cache_key] = bookmarks_cache

        return bookmarks_cache
开发者ID:10clouds,项目名称:edx-platform,代码行数:24,代码来源:services.py

示例11: __init__

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
 def __init__(self, **kwargs):
     request_cache_dict = RequestCache.get_request_cache().data
     services = kwargs.setdefault('services', {})
     services['user_tags'] = UserTagsService(self)
     services['partitions'] = LmsPartitionService(
         user=kwargs.get('user'),
         course_id=kwargs.get('course_id'),
         track_function=kwargs.get('track_function', None),
         cache=request_cache_dict
     )
     services['library_tools'] = LibraryToolsService(modulestore())
     services['fs'] = xblock.reference.plugins.FSService()
     services['settings'] = SettingsService()
     self.request_token = kwargs.pop('request_token', None)
     super(LmsModuleSystem, self).__init__(**kwargs)
开发者ID:Certific-NET,项目名称:edx-platform,代码行数:17,代码来源:runtime.py

示例12: __init__

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
 def __init__(self, **kwargs):
     request_cache_dict = RequestCache.get_request_cache().data
     services = kwargs.setdefault('services', {})
     services['fs'] = xblock.reference.plugins.FSService()
     services['i18n'] = ModuleI18nService
     services['library_tools'] = LibraryToolsService(modulestore())
     services['partitions'] = PartitionService(
         course_id=kwargs.get('course_id'),
         cache=request_cache_dict
     )
     store = modulestore()
     services['settings'] = SettingsService()
     services['user_tags'] = UserTagsService(self)
     if badges_enabled():
         services['badging'] = BadgingService(course_id=kwargs.get('course_id'), modulestore=store)
     self.request_token = kwargs.pop('request_token', None)
     super(LmsModuleSystem, self).__init__(**kwargs)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:19,代码来源:runtime.py

示例13: _providers_for_course

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def _providers_for_course(cls, course):
        """
        Return a filtered list of enabled providers based
        on the course passed in. Cache this result per request to avoid
        needing to call the provider filter api hundreds of times.

        Arguments:
            course: The course XBlock
        """
        request_cache = RequestCache.get_request_cache()
        enabled_providers = request_cache.data.get(
            ENABLED_OVERRIDE_PROVIDERS_KEY, NOTSET
        )
        if enabled_providers == NOTSET:
            enabled_providers = tuple(
                (provider_class for provider_class in cls.provider_classes if provider_class.enabled_for(course))
            )
            request_cache.data[ENABLED_OVERRIDE_PROVIDERS_KEY] = enabled_providers

        return enabled_providers
开发者ID:189140879,项目名称:edx-platform,代码行数:22,代码来源:field_overrides.py

示例14: create_modulestore_instance

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
def create_modulestore_instance(engine, content_store, doc_store_config, options, i18n_service=None, fs_service=None):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    FUNCTION_KEYS = ['render_template']
    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = get_cache('mongo_metadata_inheritance')
    except InvalidCacheBackendError:
        metadata_inheritance_cache = get_cache('default')

    if issubclass(class_, MixedModuleStore):
        _options['create_modulestore_instance'] = create_modulestore_instance

    if issubclass(class_, BranchSettingMixin):
        _options['branch_setting_func'] = _get_modulestore_branch_setting

    return class_(
        contentstore=content_store,
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
        xblock_select=getattr(settings, 'XBLOCK_SELECT_FUNCTION', None),
        doc_store_config=doc_store_config,
        i18n_service=i18n_service or ModuleI18nService(),
        fs_service=fs_service or xblock.reference.plugins.FSService(),
        **_options
    )
开发者ID:CDOT-EDX,项目名称:edx-platform,代码行数:43,代码来源:django.py

示例15: _providers_for_block

# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import get_request_cache [as 别名]
    def _providers_for_block(cls, block):
        """
        Computes a list of enabled providers based on the given XBlock.
        The result is cached per request to avoid the overhead incurred
        by filtering override providers hundreds of times.

        Arguments:
            block: An XBlock
        """
        course_id = unicode(block.location.course_key)
        cache_key = ENABLED_MODULESTORE_OVERRIDE_PROVIDERS_KEY.format(course_id=course_id)

        request_cache = RequestCache.get_request_cache()
        enabled_providers = request_cache.data.get(cache_key)

        if enabled_providers is None:
            enabled_providers = [
                provider_class for provider_class in cls.provider_classes if provider_class.enabled_for(block)
            ]
            request_cache.data[cache_key] = enabled_providers

        return enabled_providers
开发者ID:dehamzah,项目名称:edx-platform,代码行数:24,代码来源:field_overrides.py


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