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


Python models.SiteConfiguration类代码示例

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


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

示例1: get_lms_link_for_item

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,代码行数:34,代码来源:utils.py

示例2: test_get_site_for_org

    def test_get_site_for_org(self):
        """
        Test that get_value_for_org returns correct value for any given key.
        """
        # add SiteConfiguration to database
        config1 = SiteConfigurationFactory.create(
            site=self.site,
            values=self.test_config1,
        )
        config2 = SiteConfigurationFactory.create(
            site=self.site2,
            values=self.test_config2,
        )

        # Make sure entry is saved and retrieved correctly
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org(self.test_config1['course_org_filter']),
            config1,
        )
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org(self.test_config2['course_org_filter']),
            config2,
        )
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org('something else'),
            None,
        )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:27,代码来源:test_models.py

示例3: _site_from_org

 def _site_from_org(cls, org):
     configuration = SiteConfiguration.get_configuration_for_org(org, select_related=['site'])
     if configuration is None:
         try:
             return Site.objects.get(id=settings.SITE_ID)
         except Site.DoesNotExist:
             return RequestSite(crum.get_current_request())
     else:
         return configuration.site
开发者ID:mitocw,项目名称:edx-platform,代码行数:9,代码来源:models.py

示例4: test_get_all_orgs_returns_only_enabled

    def test_get_all_orgs_returns_only_enabled(self):
        """
        Test that get_all_orgs returns only those orgs whose configurations are enabled.
        """
        expected_orgs = [self.test_config2["course_org_filter"]]
        # add SiteConfiguration to database
        SiteConfigurationFactory.create(site=self.site, values=self.test_config1, enabled=False)
        SiteConfigurationFactory.create(site=self.site2, values=self.test_config2)

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertListEqual(list(SiteConfiguration.get_all_orgs()), expected_orgs)
开发者ID:hastexo,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例5: test_get_all_orgs

    def test_get_all_orgs(self):
        """
        Test that get_all_orgs returns all orgs from site configuration.
        """
        expected_orgs = [self.test_config1["course_org_filter"], self.test_config2["course_org_filter"]]
        # add SiteConfiguration to database
        SiteConfigurationFactory.create(site=self.site, values=self.test_config1)
        SiteConfigurationFactory.create(site=self.site2, values=self.test_config2)

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertListEqual(list(SiteConfiguration.get_all_orgs()), expected_orgs)
开发者ID:hastexo,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例6: get_value_for_org

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,代码行数:20,代码来源:helpers.py

示例7: get_all_orgs

def get_all_orgs():
    """
    This returns all of the orgs that are considered in site configurations or microsite configuration,
    This can be used, for example, to do filtering.

    Returns:
        A list of all organizations present in either microsite configuration or site configuration.
    """
    site_configuration_orgs = SiteConfiguration.get_all_orgs()
    microsite_orgs = microsite.get_all_orgs()

    return site_configuration_orgs.union(microsite_orgs)
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:12,代码来源:helpers.py

示例8: get_all_orgs

def get_all_orgs():
    """
    This returns all of the orgs that are considered in site configurations or microsite configuration,
    This can be used, for example, to do filtering.

    Returns:
        A list of all organizations present in either microsite configuration or site configuration.
    """
    # Import is placed here to avoid model import at project startup.
    from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
    site_configuration_orgs = SiteConfiguration.get_all_orgs()
    microsite_orgs = microsite.get_all_orgs()

    return site_configuration_orgs.union(microsite_orgs)
开发者ID:edx,项目名称:edx-platform,代码行数:14,代码来源:helpers.py

示例9: get_lms_link_for_item

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,代码行数:37,代码来源:utils.py

示例10: get_lms_link_for_certificate_web_view

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,代码行数:18,代码来源:utils.py

示例11: retrieve_last_sitewide_block_completed

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,代码行数:72,代码来源:utils.py

示例12: test_get_value_for_org

    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,代码行数:73,代码来源:test_models.py


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