← Back to team overview

openlp-core team mailing list archive

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

 

mahfiaz has proposed merging lp:~mahfiaz/openlp/formatting_tags_unicode into lp:openlp.

Requested reviews:
  Tim Bentley (trb143)
Related bugs:
  Bug #802159 in OpenLP: "Display Tag description does not en/decode German Umlauts correctly"
  https://bugs.launchpad.net/openlp/+bug/802159

For more details, see:
https://code.launchpad.net/~mahfiaz/openlp/formatting_tags_unicode/+merge/85463

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.
-- 
https://code.launchpad.net/~mahfiaz/openlp/formatting_tags_unicode/+merge/85463
Your team OpenLP Core is subscribed to branch lp:openlp.
=== 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:16:25 +0000
@@ -149,11 +149,17 @@
         tags = []
         for tag in FormattingTags.html_expands:
             if not tag[u'protected'] and not tag.get(u'temporary'):
-                tags.append(tag)
-        # Remove key 'temporary' from tags. It is not needed to be saved.
-        for tag in tags:
-            if u'temporary' in tag:
-                del tag[u'temporary']
+                # Using dict ensures that copy is made and encoding of values
+                # a little later does not affect tags in the original list
+                tags.append(dict(tag))
+                tag = tags[-1]
+                # Remove key 'temporary' from tags.
+                # It is not needed to be saved.
+                if u'temporary' in tag:
+                    del tag[u'temporary']
+                for element in tag:
+                    if isinstance(tag[element], unicode):
+                        tag[element] = tag[element].encode('utf8')
         # Formatting Tags were also known as display tags.
         QtCore.QSettings().setValue(u'displayTags/html_tags',
             QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
@@ -171,9 +177,13 @@
         user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
             QtCore.QVariant(u'')).toString()
         # cPickle only accepts str not unicode strings
-        user_expands_string = str(unicode(user_expands).encode(u'utf8'))
+        user_expands_string = str(user_expands)
         if user_expands_string:
             user_tags = cPickle.loads(user_expands_string)
+            for tag in user_tags:
+                for element in tag:
+                    if isinstance(tag[element], str):
+                        tag[element] = tag[element].decode('utf8')
             # If we have some user ones added them as well
             FormattingTags.add_html_tags(user_tags)
 


Follow ups