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

Proposed by mahfiaz
Status: Superseded
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
Tim Bentley Needs Fixing
Review via email: mp+85407@code.launchpad.net

This proposal has been superseded by a proposal from 2011-12-13.

Description of the change

Fix for bug #802159, not decoding of utf8 decoded values of custom display tags.

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

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

review: Needs Fixing
1831. By mahfiaz

No silly name abbreviations anymore.

Unmerged revisions

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-12 23:06:24 +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 e in tag:
22+ if isinstance(tag[e], unicode):
23+ tag[e] = tag[e].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 e in tag:
37+ if isinstance(tag[e], str):
38+ tag[e] = tag[e].decode('utf8')
39 # If we have some user ones added them as well
40 FormattingTags.add_html_tags(user_tags)
41