Merge lp:~mahfiaz/openlp/formatting_tags_unicode into lp:openlp

Proposed by mahfiaz
Status: Merged
Approved by: Raoul Snyman
Approved revision: 1831
Merged at revision: 1835
Proposed branch: lp:~mahfiaz/openlp/formatting_tags_unicode
Merge into: lp:openlp
Diff against target: 40 lines (+16/-6)
1 file modified
openlp/core/lib/formattingtags.py (+16/-6)
To merge this branch: bzr merge lp:~mahfiaz/openlp/formatting_tags_unicode
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Tim Bentley Approve
Review via email: mp+85463@code.launchpad.net

This proposal supersedes a proposal from 2011-12-12.

Description of the change

Fix for bug #802159, not decoding of utf8 decoded values of custom display tags, resulting of reencoding the same string on every save which makes the string wrong.

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

should use "element" instead of "e".
Unable to test as I do not have any non UK based themes and songs.

review: Needs Fixing
Revision history for this message
Tim Bentley (trb143) wrote :

From a style perspective

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Tried to reproduce from the steps in the bug report and couldn't. Works for me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/lib/formattingtags.py'
--- openlp/core/lib/formattingtags.py 2011-09-22 20:30:15 +0000
+++ openlp/core/lib/formattingtags.py 2011-12-13 11:26:29 +0000
@@ -149,11 +149,17 @@
149 tags = []149 tags = []
150 for tag in FormattingTags.html_expands:150 for tag in FormattingTags.html_expands:
151 if not tag[u'protected'] and not tag.get(u'temporary'):151 if not tag[u'protected'] and not tag.get(u'temporary'):
152 tags.append(tag)152 # Using dict ensures that copy is made and encoding of values
153 # Remove key 'temporary' from tags. It is not needed to be saved.153 # a little later does not affect tags in the original list
154 for tag in tags:154 tags.append(dict(tag))
155 if u'temporary' in tag:155 tag = tags[-1]
156 del tag[u'temporary']156 # Remove key 'temporary' from tags.
157 # It is not needed to be saved.
158 if u'temporary' in tag:
159 del tag[u'temporary']
160 for element in tag:
161 if isinstance(tag[element], unicode):
162 tag[element] = tag[element].encode('utf8')
157 # Formatting Tags were also known as display tags.163 # Formatting Tags were also known as display tags.
158 QtCore.QSettings().setValue(u'displayTags/html_tags',164 QtCore.QSettings().setValue(u'displayTags/html_tags',
159 QtCore.QVariant(cPickle.dumps(tags) if tags else u''))165 QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
@@ -171,9 +177,13 @@
171 user_expands = QtCore.QSettings().value(u'displayTags/html_tags',177 user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
172 QtCore.QVariant(u'')).toString()178 QtCore.QVariant(u'')).toString()
173 # cPickle only accepts str not unicode strings179 # cPickle only accepts str not unicode strings
174 user_expands_string = str(unicode(user_expands).encode(u'utf8'))180 user_expands_string = str(user_expands)
175 if user_expands_string:181 if user_expands_string:
176 user_tags = cPickle.loads(user_expands_string)182 user_tags = cPickle.loads(user_expands_string)
183 for tag in user_tags:
184 for element in tag:
185 if isinstance(tag[element], str):
186 tag[element] = tag[element].decode('utf8')
177 # If we have some user ones added them as well187 # If we have some user ones added them as well
178 FormattingTags.add_html_tags(user_tags)188 FormattingTags.add_html_tags(user_tags)
179189