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


Python SiteConfiguration.get_value_for_org方法代码示例

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


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

示例1: get_lms_link_for_item

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
def get_lms_link_for_item(location, preview=False):
    """
    Returns an LMS link to the course with a jump_to to the provided location.

    :param location: the location to jump to
    :param preview: True if the preview version of LMS should be returned. Default value is false.
    """
    assert isinstance(location, UsageKey)

    # checks LMS_BASE value in site configuration for the given course_org_filter(org)
    # if not found returns settings.LMS_BASE
    lms_base = SiteConfiguration.get_value_for_org(
        location.org,
        "LMS_BASE",
        settings.LMS_BASE
    )

    if lms_base is None:
        return None

    if preview:
        # checks PREVIEW_LMS_BASE value in site configuration for the given course_org_filter(org)
        # if not found returns settings.FEATURES.get('PREVIEW_LMS_BASE')
        lms_base = SiteConfiguration.get_value_for_org(
            location.org,
            "PREVIEW_LMS_BASE",
            settings.FEATURES.get('PREVIEW_LMS_BASE')
        )

    return u"//{lms_base}/courses/{course_key}/jump_to/{location}".format(
        lms_base=lms_base,
        course_key=location.course_key.to_deprecated_string(),
        location=location.to_deprecated_string(),
    )
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:36,代码来源:utils.py

示例2: get_lms_link_for_item

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
def get_lms_link_for_item(location, preview=False):
    """
    Returns an LMS link to the course with a jump_to to the provided location.

    :param location: the location to jump to
    :param preview: True if the preview version of LMS should be returned. Default value is false.
    """
    assert isinstance(location, UsageKey)

    # checks LMS_BASE value in site configuration for the given course_org_filter(org)
    # if not found returns settings.LMS_BASE
    lms_base = SiteConfiguration.get_value_for_org(
        location.org,
        "LMS_BASE",
        microsite.get_value_for_org(location.org, 'SITE_NAME', settings.LMS_BASE),
    )

    if lms_base is None:
        return None

    # eduNEXT Disable preview for now (not microsite aware), it will redirect to a normal course.
    preview = False

    if preview:
        # checks PREVIEW_LMS_BASE value in site configuration for the given course_org_filter(org)
        # if not found returns settings.FEATURES.get('PREVIEW_LMS_BASE')
        lms_base = SiteConfiguration.get_value_for_org(
            location.org,
            "PREVIEW_LMS_BASE",
            settings.FEATURES.get('PREVIEW_LMS_BASE')
        )

    return u"//{lms_base}/courses/{course_key}/jump_to/{location}".format(
        lms_base=lms_base,
        course_key=text_type(location.course_key),
        location=text_type(location),
    )
开发者ID:eduNEXT,项目名称:edunext-platform,代码行数:39,代码来源:utils.py

示例3: get_lms_link_for_certificate_web_view

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
def get_lms_link_for_certificate_web_view(user_id, course_key, mode):
    """
    Returns the url to the certificate web view.
    """
    assert isinstance(course_key, CourseKey)

    # checks LMS_BASE value in SiteConfiguration against course_org_filter if not found returns settings.LMS_BASE
    lms_base = SiteConfiguration.get_value_for_org(course_key.org, "LMS_BASE", settings.LMS_BASE)

    if lms_base is None:
        return None

    return u"//{certificate_web_base}/certificates/user/{user_id}/course/{course_id}?preview={mode}".format(
        certificate_web_base=lms_base,
        user_id=user_id,
        course_id=unicode(course_key),
        mode=mode
    )
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:20,代码来源:utils.py

示例4: get_value_for_org

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
def get_value_for_org(org, val_name, default=None):
    """
    This returns a configuration value for a site configuration or microsite configuration
    which has an org_filter that matches with the argument.

    Args:
        org (str): Course org filter, this value will be used to filter out the correct site configuration.
        name (str): Name of the key for which to return configuration value.
        default: default value to return if key is not present in the configuration

    Returns:
        Configuration value for the given key.

    """
    # Here we first look for the asked org inside site configuration, and if org is not present in site configuration
    # then we go ahead and look it inside microsite configuration.
    if SiteConfiguration.has_org(org):
        return SiteConfiguration.get_value_for_org(org, val_name, default)
    else:
        return microsite.get_value_for_org(org, val_name, default)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:22,代码来源:helpers.py

示例5: retrieve_last_sitewide_block_completed

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
def retrieve_last_sitewide_block_completed(user):
    """
    Completion utility
    From a string 'username' or object User retrieve
    the last course block marked as 'completed' and construct a URL

    :param user: obj(User)
    :return: block_lms_url

    """
    if not completion_waffle.waffle().is_enabled(completion_waffle.ENABLE_COMPLETION_TRACKING):
        return

    latest_completions_by_course = BlockCompletion.latest_blocks_completed_all_courses(user)

    known_site_configs = [
        other_site_config.get_value('course_org_filter') for other_site_config in SiteConfiguration.objects.all()
        if other_site_config.get_value('course_org_filter')
    ]

    current_site_configuration = get_config_value_from_site_or_settings(
        name='course_org_filter',
        site=get_current_site()
    )

    # courses.edx.org has no 'course_org_filter'
    # however the courses within DO, but those entries are not found in
    # known_site_configs, which are White Label sites
    # This is necessary because the WL sites and courses.edx.org
    # have the same AWS RDS mySQL instance
    candidate_course = None
    candidate_block_key = None
    latest_date = None
    # Go through dict, find latest
    for course, [modified_date, block_key] in latest_completions_by_course.items():
        if not current_site_configuration:
            # This is a edx.org
            if course.org in known_site_configs:
                continue
            if not latest_date or modified_date > latest_date:
                candidate_course = course
                candidate_block_key = block_key
                latest_date = modified_date

        else:
            # This is a White Label site, and we should find candidates from the same site
            if course.org not in current_site_configuration:
                # Not the same White Label, or a edx.org course
                continue
            if not latest_date or modified_date > latest_date:
                candidate_course = course
                candidate_block_key = block_key
                latest_date = modified_date

    if not candidate_course:
        return

    lms_root = SiteConfiguration.get_value_for_org(candidate_course.org, "LMS_ROOT_URL", settings.LMS_ROOT_URL)

    try:
        item = modulestore().get_item(candidate_block_key, depth=1)
    except ItemNotFoundError:
        item = None

    if not (lms_root and item):
        return

    return u"{lms_root}/courses/{course_key}/jump_to/{location}".format(
        lms_root=lms_root,
        course_key=text_type(item.location.course_key),
        location=text_type(item.location),
    )
开发者ID:mitocw,项目名称:edx-platform,代码行数:74,代码来源:utils.py

示例6: test_get_value_for_org

# 需要导入模块: from openedx.core.djangoapps.site_configuration.models import SiteConfiguration [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.models.SiteConfiguration import get_value_for_org [as 别名]
    def test_get_value_for_org(self):
        """
        Test that get_value_for_org returns correct value for any given key.
        """
        # add SiteConfiguration to database
        SiteConfigurationFactory.create(site=self.site, values=self.test_config1)
        SiteConfigurationFactory.create(site=self.site2, values=self.test_config2)

        # Make sure entry is saved and retrieved correctly
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config1["course_org_filter"], "university"),
            self.test_config1["university"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config1["course_org_filter"], "platform_name"),
            self.test_config1["platform_name"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config1["course_org_filter"], "SITE_NAME"),
            self.test_config1["SITE_NAME"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config1["course_org_filter"], "css_overrides_file"),
            self.test_config1["css_overrides_file"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config1["course_org_filter"], "ENABLE_MKTG_SITE"),
            self.test_config1["ENABLE_MKTG_SITE"],
        )

        # Make sure entry is saved and retrieved correctly
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config2["course_org_filter"], "university"),
            self.test_config2["university"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config2["course_org_filter"], "platform_name"),
            self.test_config2["platform_name"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config2["course_org_filter"], "SITE_NAME"),
            self.test_config2["SITE_NAME"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config2["course_org_filter"], "css_overrides_file"),
            self.test_config2["css_overrides_file"],
        )
        self.assertEqual(
            SiteConfiguration.get_value_for_org(self.test_config2["course_org_filter"], "ENABLE_MKTG_SITE"),
            self.test_config2["ENABLE_MKTG_SITE"],
        )

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertEqual(
            SiteConfiguration.get_value_for_org(
                self.test_config1["course_org_filter"], "non-existent", "dummy-default-value"
            ),
            "dummy-default-value",
        )

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertEqual(
            SiteConfiguration.get_value_for_org(
                self.test_config2["course_org_filter"], "non-existent", "dummy-default-value"
            ),
            "dummy-default-value",
        )

        # Test that the default value is returned if org is not found in the configuration
        self.assertEqual(
            SiteConfiguration.get_value_for_org("non-existent-org", "platform_name", "dummy-default-value"),
            "dummy-default-value",
        )
开发者ID:hastexo,项目名称:edx-platform,代码行数:75,代码来源:test_models.py


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