def testThemeRetrieval(self): """Checks that the correct theme is retrieved based on the settings.""" # Store settings for later. saved_theme = settings.MAKAHIKI_THEME saved_theme_settings = settings.MAKAHIKI_THEME_SETTINGS # Create test settings. settings.MAKAHIKI_THEME = "default" settings.MAKAHIKI_THEME_SETTINGS = { "default": { "widgetBackgroundColor": '#F5F3E5', "widgetHeaderColor": '#459E00', "widgetHeaderTextColor": 'white', "widgetTextColor": '#312E25', "widgetTextFont": 'Ariel, sans serif', "windowNavBarColor": '#2F6B00', }, "test": { "widgetBackgroundColor": 'white', "widgetHeaderColor": 'black', "widgetHeaderTextColor": 'white', "widgetTextColor": 'black', "widgetTextFont": 'Ariel, sans serif', "windowNavBarColor": 'green', }, } theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that we can retrieve the default theme.") settings.MAKAHIKI_THEME = "test" theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["test"], "Check that we can retrieve the test theme.") settings.MAKAHIKI_THEME = "foo" theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that an unknown theme returns the default.") settings.MAKAHIKI_THEME = None theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that no theme returns the default.") # Restore settings settings.MAKAHIKI_THEME = saved_theme settings.MAKAHIKI_THEME_SETTINGS = saved_theme_settings
def testThemeRetrieval(self): """Checks that the correct theme is retrieved based on the settings.""" # Store settings for later. saved_theme = settings.MAKAHIKI_THEME saved_theme_settings = settings.MAKAHIKI_THEME_SETTINGS # Create test settings. settings.MAKAHIKI_THEME = "default" settings.MAKAHIKI_THEME_SETTINGS = { "default" : { "widgetBackgroundColor" : '#F5F3E5', "widgetHeaderColor" : '#459E00', "widgetHeaderTextColor" : 'white', "widgetTextColor" : '#312E25', "widgetTextFont" : 'Ariel, sans serif', "windowNavBarColor" : '#2F6B00', }, "test" : { "widgetBackgroundColor" : 'white', "widgetHeaderColor" : 'black', "widgetHeaderTextColor" : 'white', "widgetTextColor" : 'black', "widgetTextFont" : 'Ariel, sans serif', "windowNavBarColor" : 'green', }, } theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that we can retrieve the default theme.") settings.MAKAHIKI_THEME = "test" theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["test"], "Check that we can retrieve the test theme.") settings.MAKAHIKI_THEME = "foo" theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that an unknown theme returns the default.") settings.MAKAHIKI_THEME = None theme, contents = get_theme() self.assertEqual(contents, settings.MAKAHIKI_THEME_SETTINGS["default"], "Check that no theme returns the default.") # Restore settings settings.MAKAHIKI_THEME = saved_theme settings.MAKAHIKI_THEME_SETTINGS = saved_theme_settings
def competition(request): """Provides access to standard competition constants within a template.""" user = request.user # We may want to retrieve theme settings for insertion into CSS. theme_name, theme_dict = get_theme() # Get user-specific information. floor_count = Floor.objects.count() overall_member_count = Profile.objects.count() floor_member_count = None quests = None notifications = None if user.is_authenticated(): quests = get_quests(user) notifications = get_unread_notifications(user, limit=3) if user.get_profile().floor: floor_member_count = user.get_profile().floor.profile_set.count() # Get current round info. current_round = get_current_round() or "Overall" # Get Facebook info. try: facebook_app_id = settings.FACEBOOK_APP_ID except AttributeError: facebook_app_id = None return { "STATIC_URL": settings.STATIC_URL, "COMPETITION_NAME": settings.COMPETITION_NAME, "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point", "THEME_NAME": theme_name, "THEME": theme_dict, "FLOOR_COUNT": floor_count, "FLOOR_MEMBER_COUNT": floor_member_count, "OVERALL_MEMBER_COUNT": overall_member_count, "ROUNDS": get_rounds_for_header(), "FLOOR_LABEL": get_floor_label(), "CURRENT_ROUND": current_round, "CURRENT_ROUND_INFO": get_current_round_info(), "FACEBOOK_APP_ID": facebook_app_id, "QUESTS": quests, "NOTIFICATIONS": notifications, "IN_COMPETITION": in_competition(), "SPREADSHEETS": { "THIRTY_DAYS": settings.ENERGY_THIRTY_DAYS_URL, "ENERGY_GOAL": settings.ENERGY_GOAL_URL, "POWER": settings.POWER_GAUGE_URL, } }
def competition(request): """Provides access to standard competition constants within a template.""" user = request.user # We may want to retrieve theme settings for insertion into CSS. theme_name, theme_dict = get_theme() # Get user-specific information. floor_count = Floor.objects.count() overall_member_count = Profile.objects.count() floor_member_count = None quests = None quest_help = None notifications = None # Try to load quest_help from the database. try: quest_help = HelpTopic.objects.get(slug="quests", category="widget") except HelpTopic.DoesNotExist: pass if user.is_authenticated(): quests = get_quests(user) notifications = get_unread_notifications(user, limit=3) if user.get_profile().floor: floor_member_count = user.get_profile().floor.profile_set.count() # Get current round info. current_round = get_current_round() # Get Facebook info. try: facebook_app_id = settings.FACEBOOK_APP_ID except AttributeError: facebook_app_id = None return { "COMPETITION_NAME": settings.COMPETITION_NAME, "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point", "THEME_NAME": theme_name, "THEME": theme_dict, "FLOOR_COUNT": floor_count, "FLOOR_MEMBER_COUNT": floor_member_count, "OVERALL_MEMBER_COUNT": overall_member_count, "ROUNDS": get_rounds_for_header(), "FLOOR_LABEL": get_floor_label(), "CURRENT_ROUND": current_round, "FACEBOOK_APP_ID": facebook_app_id, "QUESTS": quests, "QUEST_HELP": quest_help, "NOTIFICATIONS": notifications, }