quick frontend (chat): added a getlocale method and changed self.day_change calculation for pyjamas compatibility
This commit is contained in:
parent
40b71e6f80
commit
cc17c2869f
1 changed files with 9 additions and 3 deletions
|
|
@ -25,8 +25,13 @@ from sat_frontends.quick_frontend import quick_widgets
|
|||
from sat_frontends.quick_frontend.constants import Const as C
|
||||
from collections import OrderedDict
|
||||
from sat_frontends.tools import jid
|
||||
import locale
|
||||
import time
|
||||
try:
|
||||
from locale import getlocale
|
||||
except ImportError:
|
||||
# FIXME: pyjamas workaround
|
||||
getlocale = lambda x: (None, 'utf-8')
|
||||
|
||||
|
||||
ROOM_USER_JOINED = 'ROOM_USER_JOINED'
|
||||
ROOM_USER_LEFT = 'ROOM_USER_LEFT'
|
||||
|
|
@ -107,7 +112,7 @@ class Message(object):
|
|||
# if the message was sent before today, we print the full date
|
||||
timestamp = time.localtime(self.timestamp)
|
||||
time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
|
||||
return time.strftime(time_format, timestamp).decode(locale.getlocale()[1])
|
||||
return time.strftime(time_format, timestamp).decode(getlocale()[1])
|
||||
|
||||
def getNick(self, entity):
|
||||
"""Return nick of an entity when possible"""
|
||||
|
|
@ -201,7 +206,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.messages = OrderedDict() # key: uid, value: Message instance
|
||||
self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
|
||||
self.subject = subject
|
||||
self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time
|
||||
lt = time.localtime()
|
||||
self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time
|
||||
|
||||
def postInit(self):
|
||||
"""Method to be called by frontend after widget is initialised
|
||||
|
|
|
|||
Loading…
Reference in a new issue