コード例 #1
0
ファイル: utils.py プロジェクト: jmiere/edx-platform
def get_enterprise_sidebar_context(enterprise_customer, is_proxy_login):
    """
    Get context information for enterprise sidebar for the given enterprise customer.

    Args:
        enterprise_customer (dict): customer data from enterprise-customer endpoint, cached
        is_proxy_login (bool): If True, use proxy login welcome template

    Returns: Enterprise Sidebar Context with the following key-value pairs.
    {
        'enterprise_name': 'Enterprise Name',
        'enterprise_logo_url': 'URL of the enterprise logo image',
        'enterprise_branded_welcome_string': 'Human readable welcome message customized for the enterprise',
        'platform_welcome_string': 'Human readable welcome message for an enterprise learner',
    }
    """
    platform_name = configuration_helpers.get_value('PLATFORM_NAME',
                                                    settings.PLATFORM_NAME)

    branding_configuration = enterprise_customer.get('branding_configuration',
                                                     {})
    logo_url = branding_configuration.get('logo', '') if isinstance(
        branding_configuration, dict) else ''

    if is_proxy_login:
        branded_welcome_template = configuration_helpers.get_value(
            'ENTERPRISE_PROXY_LOGIN_WELCOME_TEMPLATE',
            settings.ENTERPRISE_PROXY_LOGIN_WELCOME_TEMPLATE)
    else:
        branded_welcome_template = configuration_helpers.get_value(
            'ENTERPRISE_SPECIFIC_BRANDED_WELCOME_TEMPLATE',
            settings.ENTERPRISE_SPECIFIC_BRANDED_WELCOME_TEMPLATE)

    branded_welcome_string = Text(branded_welcome_template).format(
        start_bold=HTML('<b>'),
        end_bold=HTML('</b>'),
        line_break=HTML('<br/>'),
        enterprise_name=enterprise_customer['name'],
        platform_name=platform_name,
        privacy_policy_link_start=HTML(
            "<a href='{pp_url}' rel='noopener' target='_blank'>").format(
                pp_url=get_privacy_url()),
        privacy_policy_link_end=HTML("</a>"),
    )

    platform_welcome_template = configuration_helpers.get_value(
        'ENTERPRISE_PLATFORM_WELCOME_TEMPLATE',
        settings.ENTERPRISE_PLATFORM_WELCOME_TEMPLATE)
    platform_welcome_string = platform_welcome_template.format(
        platform_name=platform_name)

    return {
        'enterprise_name': enterprise_customer['name'],
        'enterprise_logo_url': logo_url,
        'enterprise_branded_welcome_string': branded_welcome_string,
        'platform_welcome_string': platform_welcome_string,
    }
コード例 #2
0
    def test_enterprise_register(self, url_name, ec_present, ec_name, logo_url,
                                 is_proxy, mock_get_ec):
        """
        Verify that when an EnterpriseCustomer is received on the login and register views,
        the appropriate sidebar is rendered.
        """
        if ec_present:
            mock_get_ec.return_value = {
                'name': ec_name,
                'branding_configuration': {
                    'logo': logo_url
                }
            }
        else:
            mock_get_ec.return_value = None

        params = []
        if is_proxy:
            params.append(("proxy_login", "True"))

        response = self.client.get(reverse(url_name),
                                   params,
                                   HTTP_ACCEPT="text/html")

        enterprise_sidebar_div_id = u'enterprise-content-container'

        if not ec_present:
            self.assertNotContains(response, text=enterprise_sidebar_div_id)
        else:
            self.assertContains(response, text=enterprise_sidebar_div_id)
            if is_proxy:
                welcome_message = settings.ENTERPRISE_PROXY_LOGIN_WELCOME_TEMPLATE
            else:
                welcome_message = settings.ENTERPRISE_SPECIFIC_BRANDED_WELCOME_TEMPLATE
            expected_message = Text(welcome_message).format(
                start_bold=HTML('<b>'),
                end_bold=HTML('</b>'),
                line_break=HTML('<br/>'),
                enterprise_name=ec_name,
                platform_name=settings.PLATFORM_NAME,
                privacy_policy_link_start=HTML(
                    u"<a href='{pp_url}' rel='noopener' target='_blank'>").
                format(pp_url=get_privacy_url()),
                privacy_policy_link_end=HTML("</a>"),
            )
            self.assertContains(response, expected_message)
            if logo_url:
                self.assertContains(response, logo_url)
コード例 #3
0
def get_certificate_footer_context():
    """
    Return data to be used in Certificate Footer,
    data returned should be customized according to the site configuration.
    """
    data = dict()

    # get Terms of Service and Honor Code page url
    terms_of_service_and_honor_code = branding_api.get_tos_and_honor_code_url()
    if terms_of_service_and_honor_code != branding_api.EMPTY_URL:
        data.update({'company_tos_url': terms_of_service_and_honor_code})

    # get Privacy Policy page url
    privacy_policy = branding_api.get_privacy_url()
    if privacy_policy != branding_api.EMPTY_URL:
        data.update({'company_privacy_url': privacy_policy})

    # get About page url
    about = branding_api.get_about_url()
    if about != branding_api.EMPTY_URL:
        data.update({'company_about_url': about})

    return data