diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index 808086fd8..541cd8fab 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -209,13 +209,23 @@ class Theme(object): def load_theme(self, theme): """ - Pull out the XML string formatted for human consumption + Convert the JSON file and expand it. :param theme: the theme string """ jsn = json.loads(theme) self.expand_json(jsn) + def export_theme(self): + """ + Loop through the fields and build a dictionary of them + + """ + theme_data = {} + for attr, value in self.__dict__.items(): + theme_data["{attr}".format(attr=attr)] = value + return json.dumps(theme_data) + def parse(self, xml): """ Read in an XML string and parse it. diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 3b2c19222..3fb2da1c9 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -666,7 +666,7 @@ class ThemeManager(OpenLPMixin, RegistryMixin, QtWidgets.QWidget, Ui_ThemeManage :param image_to: Where the Theme Image is to be saved to """ name = theme.theme_name - theme_pretty = json.dumps(theme, default=json_default) + theme_pretty = theme.export_theme() theme_dir = os.path.join(self.path, name) check_directory_exists(theme_dir) theme_file = os.path.join(theme_dir, name + '.json') diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index 85692f0a2..db5291d23 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -102,7 +102,7 @@ class TestTheme(TestCase): # WHEN: A theme object is created default_theme = Theme() # THEN: The default values should be correct - save_theme_json = json.dumps(default_theme, default=json_default) + save_theme_json = default_theme.export_theme() lt = Theme() lt.load_theme(save_theme_json) self.check_theme(lt) diff --git a/tests/functional/openlp_core_ui/test_thememanager.py b/tests/functional/openlp_core_ui/test_thememanager.py index 393d60ecd..a30eda7fa 100644 --- a/tests/functional/openlp_core_ui/test_thememanager.py +++ b/tests/functional/openlp_core_ui/test_thememanager.py @@ -149,14 +149,13 @@ class TestThemeManager(TestCase): theme_manager.path = self.temp_folder mocked_theme = MagicMock() mocked_theme.theme_name = 'theme 愛 name' - mocked_theme.extract_formatted_xml = MagicMock() - mocked_theme.extract_formatted_xml.return_value = 'fake theme 愛 XML'.encode() + mocked_theme.export_theme.return_value = "{}" # WHEN: Calling _write_theme with a theme with a name with special characters in it theme_manager._write_theme(mocked_theme, None, None) # THEN: It should have been created - self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.xml')), + self.assertTrue(os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')), 'Theme with special characters should have been created!') def test_over_write_message_box_yes(self):