forked from openlp/openlp
Convert formatting tags to json
This commit is contained in:
parent
d32ece04a5
commit
32c7663a45
@ -30,6 +30,7 @@
|
|||||||
Provide HTML Tag management and Formatting Tag access class
|
Provide HTML Tag management and Formatting Tag access class
|
||||||
"""
|
"""
|
||||||
import cPickle
|
import cPickle
|
||||||
|
import json
|
||||||
|
|
||||||
from openlp.core.lib import Settings, translate
|
from openlp.core.lib import Settings, translate
|
||||||
|
|
||||||
@ -66,7 +67,8 @@ class FormattingTags(object):
|
|||||||
if isinstance(tag[element], unicode):
|
if isinstance(tag[element], unicode):
|
||||||
tag[element] = tag[element].encode('utf8')
|
tag[element] = tag[element].encode('utf8')
|
||||||
# Formatting Tags were also known as display tags.
|
# Formatting Tags were also known as display tags.
|
||||||
Settings().setValue(u'displayTags/html_tags', cPickle.dumps(tags) if tags else u'')
|
Settings().setValue(u'displayTags/html_tags', json.dumps(tags) if tags else u'')
|
||||||
|
Settings().setValue(u'displayTags/html_tags_json', True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_tags():
|
def load_tags():
|
||||||
@ -159,10 +161,14 @@ class FormattingTags(object):
|
|||||||
|
|
||||||
# Formatting Tags were also known as display tags.
|
# Formatting Tags were also known as display tags.
|
||||||
user_expands = Settings().value(u'displayTags/html_tags')
|
user_expands = Settings().value(u'displayTags/html_tags')
|
||||||
|
user_format_json = Settings().value(u'displayTags/html_tags_json')
|
||||||
# cPickle only accepts str not unicode strings
|
# cPickle only accepts str not unicode strings
|
||||||
user_expands_string = str(user_expands)
|
user_expands_string = str(user_expands)
|
||||||
if user_expands_string:
|
if user_expands_string:
|
||||||
user_tags = cPickle.loads(user_expands_string)
|
if user_format_json:
|
||||||
|
user_tags = json.loads(user_expands_string)
|
||||||
|
else:
|
||||||
|
user_tags = cPickle.loads(user_expands_string)
|
||||||
for tag in user_tags:
|
for tag in user_tags:
|
||||||
for element in tag:
|
for element in tag:
|
||||||
if isinstance(tag[element], str):
|
if isinstance(tag[element], str):
|
||||||
|
@ -116,6 +116,7 @@ class Settings(QtCore.QSettings):
|
|||||||
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
|
u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT,
|
||||||
u'crashreport/last directory': u'',
|
u'crashreport/last directory': u'',
|
||||||
u'displayTags/html_tags': u'',
|
u'displayTags/html_tags': u'',
|
||||||
|
u'displayTags/html_tags_json': False,
|
||||||
u'core/audio repeat list': False,
|
u'core/audio repeat list': False,
|
||||||
u'core/auto open': False,
|
u'core/auto open': False,
|
||||||
u'core/auto preview': False,
|
u'core/auto preview': False,
|
||||||
|
@ -33,11 +33,11 @@ class TestFormattingTags(TestCase):
|
|||||||
"""
|
"""
|
||||||
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
||||||
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
||||||
patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle:
|
patch(u'openlp.core.lib.formattingtags.json') as mocked_json:
|
||||||
# GIVEN: Our mocked modules and functions.
|
# GIVEN: Our mocked modules and functions.
|
||||||
mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
|
mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate
|
||||||
mocked_settings.value.return_value = u''
|
mocked_settings.value.return_value = u''
|
||||||
mocked_cPickle.load.return_value = []
|
mocked_json.load.return_value = []
|
||||||
|
|
||||||
# WHEN: Get the display tags.
|
# WHEN: Get the display tags.
|
||||||
FormattingTags.load_tags()
|
FormattingTags.load_tags()
|
||||||
@ -54,11 +54,11 @@ class TestFormattingTags(TestCase):
|
|||||||
"""
|
"""
|
||||||
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
with patch(u'openlp.core.lib.translate') as mocked_translate, \
|
||||||
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
patch(u'openlp.core.lib.settings') as mocked_settings, \
|
||||||
patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle:
|
patch(u'openlp.core.lib.formattingtags.json') as mocked_json:
|
||||||
# GIVEN: Our mocked modules and functions.
|
# GIVEN: Our mocked modules and functions.
|
||||||
mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
|
mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
|
||||||
mocked_settings.value.return_value = u''
|
mocked_settings.value.return_value = u''
|
||||||
mocked_cPickle.loads.side_effect = [[], [TAG]]
|
mocked_json.loads.side_effect = [[], [TAG]]
|
||||||
|
|
||||||
# WHEN: Get the display tags.
|
# WHEN: Get the display tags.
|
||||||
FormattingTags.load_tags()
|
FormattingTags.load_tags()
|
||||||
|
Loading…
Reference in New Issue
Block a user