comments viewlet's format_time now returns localized time.

svn path=/plone.app.discussion/trunk/; revision=27471
This commit is contained in:
Timo Stollenwerk 2009-06-16 20:53:45 +00:00
parent de5499d996
commit 3d4343440c
3 changed files with 10 additions and 6 deletions

View File

@ -19,7 +19,7 @@ BASIC COMMENTING FUNCTIONALITY
[ ] Fix temporary commenter's image css [ ] Fix temporary commenter's image css
[ ] Make comments viewlet format_time return localized time [X] Make comments viewlet format_time return localized time
[ ] Add i18n translations [ ] Add i18n translations

View File

@ -1,4 +1,5 @@
from datetime import datetime from datetime import datetime
from DateTime import DateTime
from urllib import quote as url_quote from urllib import quote as url_quote
@ -125,10 +126,11 @@ class CommentsViewlet(ViewletBase):
return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),) return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),)
def format_time(self, time): def format_time(self, time):
# Todo: return localized time # We have to transform Python datetime into Zope DateTime
return time.strftime("%a, %d %b %Y %H:%M") # before we can call toLocalizedTime
# XXX: Not working, returns None !!! util = getToolByName(self.context, 'translation_service')
#return self.context.restrictedTraverse('@@plone').toLocalizedTime(time, long_format=True) zope_time = DateTime(time.year, time.month, time.day, time.hour, time.minute, time.second)
return util.toLocalizedTime(zope_time, long_format=True)
class AddComment(BrowserView): class AddComment(BrowserView):
"""Add a comment to a conversation """Add a comment to a conversation

View File

@ -37,7 +37,9 @@ class CommentsViewletTest(PloneTestCase):
self.viewlet = CommentsViewlet(context, request, None, None) self.viewlet = CommentsViewlet(context, request, None, None)
def test_format_time(self): def test_format_time(self):
pass python_time = datetime(2009, 02, 01, 23, 32, 03, 57)
localized_time = self.viewlet.format_time(python_time)
self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM")
def test_get_commenter_portrait(self): def test_get_commenter_portrait(self):