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
1=== modified file 'openlp/core/lib/formattingtags.py'
2--- openlp/core/lib/formattingtags.py 2011-09-22 20:30:15 +0000
3+++ openlp/core/lib/formattingtags.py 2011-12-13 11:26:29 +0000
4@@ -149,11 +149,17 @@
5 tags = []
6 for tag in FormattingTags.html_expands:
7 if not tag[u'protected'] and not tag.get(u'temporary'):
8- tags.append(tag)
9- # Remove key 'temporary' from tags. It is not needed to be saved.
10- for tag in tags:
11- if u'temporary' in tag:
12- del tag[u'temporary']
13+ # Using dict ensures that copy is made and encoding of values
14+ # a little later does not affect tags in the original list
15+ tags.append(dict(tag))
16+ tag = tags[-1]
17+ # Remove key 'temporary' from tags.
18+ # It is not needed to be saved.
19+ if u'temporary' in tag:
20+ del tag[u'temporary']
21+ for element in tag:
22+ if isinstance(tag[element], unicode):
23+ tag[element] = tag[element].encode('utf8')
24 # Formatting Tags were also known as display tags.
25 QtCore.QSettings().setValue(u'displayTags/html_tags',
26 QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
27@@ -171,9 +177,13 @@
28 user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
29 QtCore.QVariant(u'')).toString()
30 # cPickle only accepts str not unicode strings
31- user_expands_string = str(unicode(user_expands).encode(u'utf8'))
32+ user_expands_string = str(user_expands)
33 if user_expands_string:
34 user_tags = cPickle.loads(user_expands_string)
35+ for tag in user_tags:
36+ for element in tag:
37+ if isinstance(tag[element], str):
38+ tag[element] = tag[element].decode('utf8')
39 # If we have some user ones added them as well
40 FormattingTags.add_html_tags(user_tags)
41