From a8f2db58ff6bacff4362e00689aefd3352acc8e3 Mon Sep 17 00:00:00 2001 From: Philip Bauer Date: Sat, 5 May 2018 20:25:07 +0200 Subject: [PATCH] fix commenting in py3 --- plone/app/discussion/catalog.py | 8 +++++++- plone/app/discussion/comment.py | 2 +- plone/app/discussion/conversation.py | 14 +++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py index 6bbc760..73c5ab2 100644 --- a/plone/app/discussion/catalog.py +++ b/plone/app/discussion/catalog.py @@ -13,6 +13,7 @@ from Products.CMFCore.interfaces import IContentish from Products.CMFPlone.utils import safe_unicode from Products.ZCatalog.interfaces import IZCatalog +import six MAX_DESCRIPTION = 25 @@ -70,7 +71,12 @@ def title(object): @indexer(IComment) def creator(object): - return object.creator and safe_unicode(object.creator).encode('utf-8') + if not object.creator: + return + value = safe_unicode(object.creator) + if six.PY2: + return value.encode('utf8') + return value @indexer(IComment) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 7b96007..788d54d 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -148,7 +148,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, text = self.text if text is None: return '' - if isinstance(text, six.text_type): + if six.PY2 and isinstance(text, six.text_type): text = text.encode('utf8') transform = transforms.convertTo( targetMimetype, diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index e616a79..5a6ed71 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -161,7 +161,7 @@ class Conversation(Traversable, Persistent, Explicit): comment = aq_base(comment) - id = long(time.time() * 1e6) + id = int(time.time() * 1e6) while id in self._comments: id += 1 @@ -206,22 +206,22 @@ class Conversation(Traversable, Persistent, Explicit): return len(self._comments) def __contains__(self, key): - return long(key) in self._comments + return int(key) in self._comments def __getitem__(self, key): - """Get an item by its long key + """Get an item by its int key """ try: - comment_id = long(key) + comment_id = int(key) except ValueError: return return self._comments[comment_id].__of__(self) def __delitem__(self, key, suppress_container_modified=False): - """Delete an item by its long key + """Delete an item by its int key """ - key = long(key) + key = int(key) comment = self[key].__of__(self) commentator = comment.author_username @@ -260,7 +260,7 @@ class Conversation(Traversable, Persistent, Explicit): return iter(self._comments) def get(self, key, default=None): - comment = self._comments.get(long(key), default) + comment = self._comments.get(int(key), default) if comment is default: return default return comment.__of__(self)