fix commenting in py3

This commit is contained in:
Philip Bauer 2018-05-05 20:25:07 +02:00
parent a7d95a9449
commit a8f2db58ff
3 changed files with 15 additions and 9 deletions

View File

@ -13,6 +13,7 @@ from Products.CMFCore.interfaces import IContentish
from Products.CMFPlone.utils import safe_unicode from Products.CMFPlone.utils import safe_unicode
from Products.ZCatalog.interfaces import IZCatalog from Products.ZCatalog.interfaces import IZCatalog
import six
MAX_DESCRIPTION = 25 MAX_DESCRIPTION = 25
@ -70,7 +71,12 @@ def title(object):
@indexer(IComment) @indexer(IComment)
def creator(object): 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) @indexer(IComment)

View File

@ -148,7 +148,7 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
text = self.text text = self.text
if text is None: if text is None:
return '' return ''
if isinstance(text, six.text_type): if six.PY2 and isinstance(text, six.text_type):
text = text.encode('utf8') text = text.encode('utf8')
transform = transforms.convertTo( transform = transforms.convertTo(
targetMimetype, targetMimetype,

View File

@ -161,7 +161,7 @@ class Conversation(Traversable, Persistent, Explicit):
comment = aq_base(comment) comment = aq_base(comment)
id = long(time.time() * 1e6) id = int(time.time() * 1e6)
while id in self._comments: while id in self._comments:
id += 1 id += 1
@ -206,22 +206,22 @@ class Conversation(Traversable, Persistent, Explicit):
return len(self._comments) return len(self._comments)
def __contains__(self, key): def __contains__(self, key):
return long(key) in self._comments return int(key) in self._comments
def __getitem__(self, key): def __getitem__(self, key):
"""Get an item by its long key """Get an item by its int key
""" """
try: try:
comment_id = long(key) comment_id = int(key)
except ValueError: except ValueError:
return return
return self._comments[comment_id].__of__(self) return self._comments[comment_id].__of__(self)
def __delitem__(self, key, suppress_container_modified=False): 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) comment = self[key].__of__(self)
commentator = comment.author_username commentator = comment.author_username
@ -260,7 +260,7 @@ class Conversation(Traversable, Persistent, Explicit):
return iter(self._comments) return iter(self._comments)
def get(self, key, default=None): def get(self, key, default=None):
comment = self._comments.get(long(key), default) comment = self._comments.get(int(key), default)
if comment is default: if comment is default:
return default return default
return comment.__of__(self) return comment.__of__(self)