From 3cdaa260df66a58304cbcc6307db3fd6e4eaff66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 8 Feb 2014 13:04:04 +0100 Subject: [PATCH] somehow improve compatibility with the unicode mess :/ --- plone/principalsource/source.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plone/principalsource/source.py b/plone/principalsource/source.py index ee3728e..4a2470e 100644 --- a/plone/principalsource/source.py +++ b/plone/principalsource/source.py @@ -156,24 +156,26 @@ class PrincipalSource(object): if isinstance(token, unicode): token = token.encode('utf-8') - type = result_dict.get('principal_type', 'user') + object_type = result_dict.get('principal_type', 'user') value = result_dict.get('login', result_dict.get('groupid')) or id title = result_dict.get('title') or value - + # Attempt to get a title from the fullname if not set. Unfortunately, # source_users doesn't have fullname, and mutable_properties doesn't # match on login name or id when searching. if title == value: - if type == 'user': + if object_type == 'user': user = self.acl_users.getUserById(id) if user is not None: try: # XXX: user.getProperty() is PlonePAS specfic title = user.getProperty('fullname') or value + if type(title) not in (str, unicode): + title = value except AttributeError: pass - + # # Seems the groups source is a bit more intelligent, so we don't # need this. @@ -186,7 +188,12 @@ class PrincipalSource(object): # except AttributeError: # pass - return PrincipalTerm(value=value, type=type, token=token, title=title) + if type(value) is not unicode: + value = unicode(value, 'utf-8') + if type(title) is not unicode: + title = unicode(title, 'utf-8') + + return PrincipalTerm(value=value, type=object_type, token=token, title=title) @property def _search(self):