merge r47140, r47290, r47579 from davisagli-features: fix timezone handling when migrating legacy comments and when indexing

svn path=/plone.app.discussion/trunk/; revision=48358
This commit is contained in:
David Glick 2011-04-02 21:26:36 +00:00
parent 9d83b4f0e6
commit 636bca745c
5 changed files with 27 additions and 12 deletions

View File

@ -4,6 +4,14 @@ Changelog
2.0b1 (Unreleased) 2.0b1 (Unreleased)
------------------ ------------------
- Fix issue where GMT datetimes were converted into local timezone DateTimes
during indexing.
[davisagli]
- Handle timezones correctly while converting dates during the migration of
legacy comments.
[davisagli]
- When returning a comment's title, give preference to its title attribute - When returning a comment's title, give preference to its title attribute
if set. if set.
[davisagli] [davisagli]

View File

@ -15,6 +15,12 @@ from plone.app.discussion.comment import CommentFactory
from plone.app.discussion.interfaces import IConversation, IReplies, IComment from plone.app.discussion.interfaces import IConversation, IReplies, IComment
def DT2dt(DT):
"""Convert a Zope DateTime (with timezone) into a Python datetime (GMT)."""
DT = DT.toZone('GMT')
return datetime(DT.year(), DT.month(), DT.day(), DT.hour(), DT.minute(), int(DT.second()))
class View(BrowserView): class View(BrowserView):
"""Migration View """Migration View
""" """
@ -78,10 +84,8 @@ class View(BrowserView):
if email: if email:
comment.author_email = email comment.author_email = email
comment.creation_date = datetime.fromtimestamp( comment.creation_date = DT2dt(reply.creation_date)
reply.creation_date) comment.modification_date = DT2dt(reply.modification_date)
comment.modification_date = datetime.fromtimestamp(
reply.modification_date)
comment.reply_to = in_reply_to comment.reply_to = in_reply_to

View File

@ -100,7 +100,8 @@ def effective(object):
object.creation_date.day, object.creation_date.day,
object.creation_date.hour, object.creation_date.hour,
object.creation_date.minute, object.creation_date.minute,
object.creation_date.second) object.creation_date.second,
'GMT')
@indexer(IComment) @indexer(IComment)
def created(object): def created(object):
@ -110,7 +111,8 @@ def created(object):
object.creation_date.day, object.creation_date.day,
object.creation_date.hour, object.creation_date.hour,
object.creation_date.minute, object.creation_date.minute,
object.creation_date.second) object.creation_date.second,
'GMT')
@indexer(IComment) @indexer(IComment)
def modified(object): def modified(object):
@ -120,7 +122,8 @@ def modified(object):
object.modification_date.day, object.modification_date.day,
object.modification_date.hour, object.modification_date.hour,
object.modification_date.minute, object.modification_date.minute,
object.modification_date.second) object.modification_date.second,
'GMT')
# Override the conversation indexers for comments # Override the conversation indexers for comments

View File

@ -151,11 +151,11 @@ class CommentIndexersTest(PloneTestCase):
def test_dates(self): def test_dates(self):
# Test if created, modified, effective etc. are set correctly # Test if created, modified, effective etc. are set correctly
self.assertEquals(catalog.created(self.comment)(), self.assertEquals(catalog.created(self.comment)(),
DateTime(2006, 9, 17, 14, 18, 12)) DateTime(2006, 9, 17, 14, 18, 12, 'GMT'))
self.assertEquals(catalog.effective(self.comment)(), self.assertEquals(catalog.effective(self.comment)(),
DateTime(2006, 9, 17, 14, 18, 12)) DateTime(2006, 9, 17, 14, 18, 12, 'GMT'))
self.assertEquals(catalog.modified(self.comment)(), self.assertEquals(catalog.modified(self.comment)(),
DateTime(2008, 3, 12, 7, 32, 52)) DateTime(2008, 3, 12, 7, 32, 52, 'GMT'))
def test_searchable_text(self): def test_searchable_text(self):
# Test if searchable text is a concatenation of title and comment text # Test if searchable text is a concatenation of title and comment text

View File

@ -47,8 +47,8 @@ class MigrationTest(PloneTestCase):
self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim') self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim')
reply = talkback.getReplies()[0] reply = talkback.getReplies()[0]
reply.setReplyTo(self.doc) reply.setReplyTo(self.doc)
reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6) reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT')
reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7) reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT')
self.assertEquals(reply.Title(), 'My Title') self.assertEquals(reply.Title(), 'My Title')
self.assertEquals(reply.EditableBody(), 'My Text') self.assertEquals(reply.EditableBody(), 'My Text')
self.failUnless('Jim' in reply.listCreators()) self.failUnless('Jim' in reply.listCreators())