Commits

Anonymous committed 4c38ba7 Draft

ThemeEnginePlugin [ fixes #11104 ]: Current theme in custom theme admin template defaults to empty dict
Error recovery on misconfiguration in ThemeBase.is_active_theme

refs #11103 - because error on misconfiguration also affects simple theme admin panel
refs #10852 - the original ticket introducing is_active_theme API method

  • Participants
  • Parent commits 7fa863c

Comments (0)

Files changed (3)

File themeengine/admin.py

         theme_name = self.system.theme_name or 'Default'
         data['current'] = theme_name
         index = 0
-        curtheme = None
+        curtheme = {}
         for i, (k, v) in enumerate(data['themes']):
             if k == theme_name:
                 index = i

File themeengine/api.py

         themesys = self.env[ThemeEngineSystem]
         if themesys is None:
             return False
-        active_theme = themesys.theme
+        try:
+            active_theme = themesys.theme
+        except ThemeNotFound:
+            # There is no way this component can be the active theme
+            return False
         if active_theme is None:
             return False
         return active_theme.get('provider') is self

File themeengine/tests/api.py

     def get_theme_names(self):
         yield 'full'
         yield 'quick'
-        
+
     def get_theme_info(self, name):
         return dict(disable_trac_css=True)
 
         self.assertFalse(self.themesys.is_active_theme('full'))
         self.assertFalse(self.themesys.is_active_theme('quick'))
 
+    def test_theme_misconfiguration(self):
+        """Fall back to default theme on misconfiguration
+        """
+        env = self.env
+
+        env.config.set('theme', 'theme', 'wrong')
+        self.assertTrue(self.themesys.is_active_theme('default'))
+        self.assertTrue(self.themesys.is_active_theme('default', 
+                                                      self.themesys))
+        self.assertFalse(self.themesys.is_active_theme('full'))
+        self.assertFalse(self.themesys.is_active_theme('quick'))
+        self.assertFalse(QuickTheme(env).is_active_theme)
+
     def test_custom_theme_active(self):
         """Test theme and is_active_theme for custom theme
         """