def get_base_template_context(site): """ Dict with entries needed for all templates that use the base template. """ # When on LMS and a dashboard is available, use that as the dashboard url. # Otherwise, use the home url instead. try: dashboard_url = reverse('dashboard') except NoReverseMatch: dashboard_url = reverse('home') contact_mailing_address = configuration_helpers.get_value( 'CONTACT_MAILING_ADDRESS') if not contact_mailing_address: contact_mailing_address = get_config_value_from_site_or_settings( 'CONTACT_MAILING_ADDRESS', site=site, site_config_name='CONTACT_MAILING_ADDRESS') return { # Platform information 'homepage_url': marketing_link('ROOT'), 'dashboard_url': dashboard_url, 'template_revision': getattr(settings, 'EDX_PLATFORM_REVISION', None), 'platform_name': get_config_value_from_site_or_settings( 'PLATFORM_NAME', site=site, site_config_name='platform_name', ), 'contact_email': get_config_value_from_site_or_settings( 'CONTACT_EMAIL', site=site, site_config_name='contact_email'), 'contact_mailing_address': contact_mailing_address, 'social_media_urls': get_config_value_from_site_or_settings('SOCIAL_MEDIA_FOOTER_URLS', site=site), 'mobile_store_urls': get_config_value_from_site_or_settings('MOBILE_STORE_URLS', site=site), # Context processor values for dynamic theming 'edly_colors_config': get_theme_colors(), 'edly_fonts_config': configuration_helpers.get_dict('FONTS', DEFAULT_FONTS_DICT), 'edly_branding_config': configuration_helpers.get_dict('BRANDING', DEFAULT_BRANDING_DICT), # Context processor value for edly app 'edly_copyright_text': configuration_helpers.get_value('EDLY_COPYRIGHT_TEXT') }
def dynamic_theming_context(request): # pylint: disable=unused-argument """ Context processor responsible for dynamic theming. """ theming_context = {} theming_context.update({'edly_colors_config': get_theme_colors()}) theming_context.update({ 'edly_fonts_config': configuration_helpers.get_dict('FONTS', DEFAULT_FONTS_DICT) }) theming_context.update({ 'edly_branding_config': configuration_helpers.get_dict('BRANDING', DEFAULT_BRANDING_DICT) }) return theming_context
def test_get_dict(self): """ Test that get_dict returns correct value for any given key. """ # Make sure entry is saved and retrieved correctly self.assertItemsEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'], ) default = {"test1": 123, "first_name": "Test"} expected = default expected.update(test_config['REGISTRATION_EXTRA_FIELDS']) # Test that the default value is returned if the value for the given key is not found in the configuration self.assertItemsEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS", default), expected, )
def test_get_dict(self): """ Test that get_dict returns correct value for any given key. """ # Make sure entry is saved and retrieved correctly self.assertItemsEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'], ) default = {"test1": 123, "first_name": "Test"} expected = default expected.update(test_config['REGISTRATION_EXTRA_FIELDS']) # Test that the default value is returned if the value for the given key is not found in the configuration self.assertItemsEqual( configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS", default), expected, )
def get_theme_colors(): color_dict = configuration_helpers.get_dict('COLORS', DEFAULT_COLOR_DICT) primary = Colour(str(color_dict.get('primary'))) secondary = Colour(str(color_dict.get('secondary'))) primary_hover = color_dict.get('primary-hover') primary_rgb = color_dict.get('primary-rgb') primary_lighten_5p = color_dict.get('primary-lighten-5p') primary_lighten_10p = color_dict.get('primary-lighten-10p') primary_darken_5p = color_dict.get('primary-darken-5p') primary_darken_10p = color_dict.get('primary-darken-10p') secondary_hover = color_dict.get('secondary-hover') secondary_rgb = color_dict.get('secondary-rgb') secondary_lighten_5p = color_dict.get('secondary-lighten-5p') secondary_lighten_10p = color_dict.get('secondary-lighten-10p') secondary_darken_5p = color_dict.get('secondary-darken-5p') secondary_darken_10p = color_dict.get('secondary-darken-10p') colours = { 'primary': color_dict.get('primary'), 'secondary': color_dict.get('secondary'), 'primary-hover': get_hover_color(primary_hover, primary), 'primary-rgb': get_rgb_color(primary_rgb, primary), 'primary-lighten-5p': get_lighten_color(primary_lighten_5p, primary, 0.05), 'primary-lighten-10p': get_lighten_color(primary_lighten_10p, primary, 0.1), 'primary-darken-5p': get_darken_color(primary_darken_5p, primary, 0.05), 'primary-darken-10p': get_darken_color(primary_darken_10p, primary, 0.1), 'secondary-hover': get_hover_color(secondary_hover, secondary), 'secondary-rgb': get_rgb_color(secondary_rgb, secondary), 'secondary-lighten-5p': get_lighten_color(secondary_lighten_5p, secondary, 0.05), 'secondary-lighten-10p': get_lighten_color(secondary_lighten_10p, secondary, 0.1), 'secondary-darken-5p': get_darken_color(secondary_darken_5p, secondary, 0.05), 'secondary-darken-10p': get_darken_color(secondary_darken_10p, secondary, 0.1), } return colours