fix commenting in py3
This commit is contained in:
parent
a7d95a9449
commit
a8f2db58ff
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user